Skip to main content

threading

import {...} from "@canvas-commons/core/lib/threading";

Thread management.

Classes​

Interfaces​

Type Aliases​

ThreadGenerator​

type ThreadGenerator = GeneratorThreadGeneratorPromiseanyPromisableanyvoidvoidThreadany

The main generator type produced by all generator functions in Canvas Commons.

Examples

Functions​

cancel​

public cancel...tasks: ThreadGenerator[]: void

Cancel all listed tasks.

Example:

const task = yield generatorFunction();

// do something concurrently

yield* cancel(task);

Parameters

  • ...tasks: ThreadGenerator[]

    A list of tasks to cancel.


getTaskName​

public getTaskNametask: Generator: string

Parameters


isPromisable​

public isPromisablevalue: any: value is Promisableany

Parameters


isPromise​

public isPromisevalue: any: value is Promiseany

Check if the given value is a [Promise][promise].

Parameters


isThreadGenerator​

public isThreadGeneratorvalue: unknown: value is ThreadGenerator

Check if the given value is a ThreadGenerator.

Parameters


join​

public join...tasks: ThreadGenerator[]: ThreadGenerator
public joinall: boolean...tasks: ThreadGenerator[]: ThreadGenerator

Pause the current generator until all listed tasks are finished.

Examples

Parameters

  • ...tasks: ThreadGenerator[]

    A list of tasks to join.


setTaskName​

public setTaskNametask: Generatorsource: stringGeneratorunknownanyany: void

Parameters


spawn​

public spawntask: ThreadGenerator() => ThreadGenerator: ThreadGenerator

Run the given task concurrently.

Examples

Parameters

  • task: ThreadGenerator() => ThreadGenerator

    Either a generator function or a task to run.


threads​

public threadsfactory: ThreadsFactorycallback?: ThreadsCallback: ThreadGenerator

Create a context in which generators can be run concurrently.

From the perspective of the external generator, threads is executed synchronously. By default, each scene generator is wrapped in its own threads generator.

Examples

Parameters

  • factory: ThreadsFactory

    A function that returns the generator to run.

  • callback?: ThreadsCallback

    Called whenever threads are created, canceled or finished. Used for debugging purposes.