Skip to content

Added access to the coroutine context from within any function call.#117

Merged
accelerated merged 2 commits intobloomberg:masterfrom
accelerated:local_context
Sep 12, 2019
Merged

Added access to the coroutine context from within any function call.#117
accelerated merged 2 commits intobloomberg:masterfrom
accelerated:local_context

Conversation

@accelerated
Copy link
Copy Markdown
Contributor

@accelerated accelerated commented Sep 11, 2019

Signed-off-by: Alexander Damian adamian@bloomberg.net

Describe your changes

  • Add access to the coroutine context from within any function. This allows to yield, sleep or call any ICoroContext API (such as creating new coroutines) if the function is invoked from a coroutine.
  • changed inner namespace quantum::cls to quantum::local.
  • Added GenericFuture class. This facade util class can wrap any future type at runtime, when the execution context is unknown and can be determined via quantum::local::context();
    Example:
//We want to post a coroutine but this API can be called from either a regular 
//thread or a coroutine. Since we can't block inside a coroutine, the future 
//returned must be 'smart' and block only if in a thread.
GenericFuture<int> someApi(...)
{
    ... //business logic
    auto ctx = local::context(); //get coroutine context if any
    if (ctx) {
        //post via coroutine context
        return {ctx->post(...), ctx}; 
    }
    else {
        //post via dispatcher
        return dispatcher->post(...);
    }
}

// usage will be:
int i = someApi(...).get(); //if we are inside a coroutine we won't block but yield instead

Testing performed
Created specific GTEST for this scenario.

…Changed namespace cls to local

Signed-off-by: Alexander Damian <adamian@bloomberg.net>
@accelerated
Copy link
Copy Markdown
Contributor Author

@demin80 can you please take a look?

Signed-off-by: Alexander Damian <adamian@bloomberg.net>
Copy link
Copy Markdown
Contributor

@demin80 demin80 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@accelerated accelerated merged commit 6abbad9 into bloomberg:master Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants