Effection Logo

function withResolvers

thefrontside/effection

function withResolvers<T>(description?: string): WithResolvers<T>

Create an Operation and two functions to resolve or reject it, corresponding to the two parameters passed to the executor of the action constructor. This is the Effection equivalent of [Promise.withResolvers()]https

Examples

Example 1

import { once, spawn, withResolvers } from "effection";

// one may pass a type for any value (or nothing) to resolve
let ready = withResolvers<Event>();

yield* spawn(function* () {
  // do some work
  ready.resolve(yield* once(socket, "open"));
});

let event = yield* ready.operation;
console.log(event.type); // "open"

Type Parameters

T

Parameters

descriptionoptional: string

Return Type

WithResolvers<T>

an operation and its resolvers.