-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fromPromise
passes signal to creator (#4832)
* add support for `fromPromise` passing signal * wordsmithing * ensure every promise actor has a unique abort controller instance, do not use done variable * bump to minor * delete controller on finish * improve tests * make tests clearer * update tests, use esnext.promise for types * ref: cleanup * catch so error is not propagated * oops, remove Deferred type * Update .changeset/sweet-sheep-arrive.md Co-authored-by: David Khourshid <[email protected]> --------- Co-authored-by: David Khourshid <[email protected]>
- Loading branch information
1 parent
d8877fe
commit 148d8fc
Showing
4 changed files
with
281 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
`fromPromise` now passes a signal into its creator function. | ||
|
||
```ts | ||
const logic = fromPromise(({ signal }) => | ||
fetch('https://api.example.com', { signal }) | ||
); | ||
``` | ||
|
||
This will be called whenever the state transitions before the promise is resolved. This is useful for cancelling the promise if the state changes. |
This file contains 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
This file contains 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
This file contains 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