-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for asynchronous invocation entry #146
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- 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.
as you said:
Other processing will get wrong entry for the context during |
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
asyncEntry
method inSph
interface andSphU
class.AsyncEntry
class 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#getAsyncContext
method and use withContextUtil#runOnContext
to do context switching in asynchronous callback.runOnContext
andreplaceContext
method inContextUtil
for context switching.For users
We can call
SphU.asyncEntry(xxx)
to entry for asynchronous invocation, thenexit
it 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.