Newer version available
You’re viewing the API reference for version 3.2.1, but the latest version is 3.4.0. The latest version include may important updates and fixes.
View Latest Versionfunction action
thefrontside/effectionfunction action<T>(enter: (resolve: Resolve<T>, reject: Reject) => () => void): Operation<T>
Create an Operation that can be either resolved (or rejected) with
a synchronous callback. This is the Effection equivalent of new Promise()
.
The action body is a function that enters the effect, and returns a function that will be called to exit the action..
For example:
let five = yield* action((resolve, reject) => {
let timeout = setTimeout(() => {
if (Math.random() > 5) {
resolve(5)
} else {
reject(new Error("bad luck!"));
}
}, 1000);
return () => clearTimeout(timeout);
});
Type Parameters
T
- type of the action's result.
Parameters
enter: (resolve: Resolve<T>, reject: Reject) => () => void
- enter and exit the action
Return Type
Operation<T>
an operation producing the resolved value, or throwing the rejected error