Effection Logo

function call

thefrontside/effection

function call<T, TArgs extends unknown[] = []>(fn: (args: TArgs) => Promise<T>): Operation<T>

Pause the current operation, async function, plain function, or operation function. The calling operation will be resumed (or errored) once call is completed.

call() is a uniform integration point for calling async functions, generator functions, and plain functions.

To call an async function:

Examples

Example 1

async function* googleSlowly() {
  return yield* call(async function() {
    await new Promise(resolve => setTimeout(resolve, 2000));
    return await fetch("https://google.com");
  });
}

or a plain function:


Example 2

yield* call(() => "a string");

Type Parameters

T

TArgs extends unknown[] = []

Parameters

fn: (...args: : TArgs) => Promise<T>

the operation, promise, async function, generator funnction, or plain function to call as part of this operation

Return Type

Operation<T>

function call<T, TArgs extends unknown[] = []>(fn: (args: TArgs) => T): Operation<T>

Type Parameters

T

TArgs extends unknown[] = []

Parameters

fn: (...args: : TArgs) => T

Return Type

Operation<T>

function call<T, TArgs extends unknown[] = []>(fn: (args: TArgs) => Operation<T>): Operation<T>

Type Parameters

T

TArgs extends unknown[] = []

Parameters

fn: (...args: : TArgs) => Operation<T>

Return Type

Operation<T>

function call<T, TArgs extends unknown[] = []>(callable: Callable<T, TArgs>, args: TArgs): Operation<T>

Type Parameters

T

TArgs extends unknown[] = []

Parameters

callable: Callable<T, TArgs>

...args: : TArgs

Return Type

Operation<T>