Effection Logo

function action

thefrontside/effection

function 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

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

Deprecated

action() used with an operation will be removed in v4.

Type Parameters

T

Parameters

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

Return Type

Operation<T>

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

Type Parameters

T

Parameters

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

Return Type

Operation<T>