function action
thefrontside/effectionCreate 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