Add support for asynchronous invocation entry#146
Merged
Conversation
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
a964e0e to
7b4be5d
Compare
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
7b4be5d to
2a3e335
Compare
Codecov Report
@@ Coverage Diff @@
## master #146 +/- ##
==========================================
+ Coverage 45.94% 48% +2.06%
- Complexity 563 639 +76
==========================================
Files 115 120 +5
Lines 3844 4081 +237
Branches 536 577 +41
==========================================
+ Hits 1766 1959 +193
- Misses 1862 1886 +24
- Partials 216 236 +20
Continue to review full report at Codecov.
|
Arlmls
pushed a commit
to Arlmls/Sentinel
that referenced
this pull request
Jan 8, 2019
- Add several `asyncEntry` method in `Sph` interface and `SphU` class. - Add a new `AsyncEntry` class for asynchronous entry representation. Some refactor for `CtEntry`. - Refactored `CtSph` and implement `asyncEntryInternal` for asynchronous entry. - Add `runOnContext` and `replaceContext` method in `ContextUtil` for context switching.
Contributor
|
as you said:
Other processing will get wrong entry for the context during |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe what this PR does / why we need it
Add support for asynchronous invocation entry so that users can use Sentinel in asynchronous logic.
Does this pull request fix one issue?
Resolves #31
Describe how you did it
Internal
asyncEntrymethod inSphinterface andSphUclass.AsyncEntryclass for asynchronous entry representation, which resembles the linkedCtEntry. The difference:SphU.asyncEntry, the created async entry is set to current context. As soon as the entry passed the slot chain (or blocked), it will be cleared from current context intermediately so that it won't affect the proceeding entries.CtSph#asyncEntryInternal, the async context inside the async entry will be initialized. We can get the async context viaAsyncEntry#getAsyncContextmethod and use withContextUtil#runOnContextto do context switching in asynchronous callback.runOnContextandreplaceContextmethod inContextUtilfor context switching.For users
We can call
SphU.asyncEntry(xxx)to entry for asynchronous invocation, thenexitit in the callback (or other place, often in different thread). If we want nested entry in asynchronous entry, we have to wrap the logic within the async context viaContextUtil.runOnContext(asyncContext, lambda).Here is an example:
Describe how to verify it
See test cases.