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(). Actions are stateless and so unlike
the new Promise() executor function, the action executor is
called every time that an action is evaluated.
The resolver must return a "finally" function that will always be called regardless of whether the action was resolved or rejected, or discarded.
Examples
Example 1
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
Parameters
executor: Executor<T>
- a function called every time that an action is evaluated
descoptional: string
Return Type
Operation<T>
an operation that will run according to executor every time it is evaluated