threading
import {...} from "@motion-canvas/core/lib/threading";
Thread management.
Classes​
Interfaces​
Type Aliases​
ThreadGenerator​
type ThreadGenerator = GeneratorThreadGeneratorPromiseanyPromisableanyvoidvoidThreadany
The main generator type produced by all generator functions in Motion Canvas.
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​
Parameters
isPromisable​
public isPromisablevalue: any: value is Promisableany
Parameters
value: any
isPromise​
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
value: unknownA possible thread
ThreadGenerator.
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​
Parameters
spawn​
public spawntask: ThreadGenerator() => ThreadGenerator: ThreadGenerator
Run the given task concurrently.
Examples
Parameters
task: ThreadGenerator() => ThreadGeneratorEither 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: ThreadsFactoryA function that returns the generator to run.
callback?: ThreadsCallbackCalled whenever threads are created, canceled or finished. Used for debugging purposes.