-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
actionAsync (red X is coveralls) #217
Conversation
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 to me! Looks really solid :)
Thanks! just improved it by fixing some edge cases such as recursivity and making sure dangling promises never leave a stale action started. I was just wondering, should this replace "asyncAction", or just use the new "actionAsync" name? |
Released as 5.5.0! |
Related to mobxjs/mobx#2118
I'd like to name it asyncAction instead, but that one is taken (although deprecated), so I named it backwards
actionAsync
Alternative syntax for async actions, similar to
flow
but more compatible withTypescript typings. Not to be confused with
asyncAction
, which is deprecated.actionAsync
can be used either as a decorator or as a function.It takes an async function that internally must use
await task(promise)
rather thanthe standard
await promise
.When using the mobx devTools, an asyncAction will emit
action
events with names like:"fetchUsers - runid 6 - step 0"
"fetchUsers - runid 6 - step 1"
"fetchUsers - runid 6 - step 2"
The
runId
represents the action instance. In other words, iffetchUsers
is invokedmultiple times concurrently, the events with the same
runid
belong together.The
step
number indicates the code block that is now being executed.Examples
As for changes from the last iteration now it uses a global awaiter "task", which allows for a decorator version.