Effection Logo

function action

thefrontside/effection

function action<T>(enter: (resolve: Resolve<T>, reject: Reject) => () => void): Operation<T>

Create an https://effection-www-pggsafb7y58a.deno.dev/api/v3/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: https://effection-www-pggsafb7y58a.deno.dev/api/v3/Resolve&lt;T>, reject: https://effection-www-pggsafb7y58a.deno.dev/api/v3/Reject) => () => void

  • enter and exit the action

Return Type

https://effection-www-pggsafb7y58a.deno.dev/api/v3/Operation&lt;T>

an operation producing the resolved value, or throwing the rejected error

function action<T>(operation: (resolve: Resolve<T>, reject: Reject) => Operation<void>): Operation<T>

function action<T>(operation: ((resolve: Resolve<T>, reject: Reject) => Operation<void>) | ((resolve: Resolve<T>, reject: Reject) => () => void)): Operation<T>