Effection Logo

function spawn

thefrontside/effection

function* spawn<T>(op: () => Operation<T>): Operation<Task<T>>

Run another operation concurrently as a child of the current one.

The spawned operation will begin executing at the next available opportunity.

Examples

Example 1

import { main, sleep, suspend, spawn } from 'effection';

await main(function*() {
  yield* spawn(function*() {
    yield* sleep(1000);
    console.log("hello");
  });
  yield* spawn(function*() {
    yield* sleep(2000);
    console.log("world");
  });
  yield* suspend();
});

Type Parameters

T the type that the spawned task evaluates to

Parameters

op: () => Operation<T>

  • the operation to run as a child of the current task

Return Type

Operation<Task<T>>

a Task representing a handle to the running operation