flow
import {...} from "@motion-canvas/core/lib/flow";
Utilities for controlling the flow and timing of an animation.
Interfaces
Functions
all
public all...tasks: ThreadGenerator[]: ThreadGenerator
Run all tasks concurrently and wait for all of them to finish.
Examples
Parameters
...tasks: ThreadGenerator[]
A list of tasks to run.
any
public any...tasks: ThreadGenerator[]: ThreadGenerator
Run all tasks concurrently and wait for any of them to finish.
Examples
Parameters
...tasks: ThreadGenerator[]
A list of tasks to run.
chain
public chain...tasks: CallbackThreadGenerator[]: ThreadGenerator
Run tasks one after another.
Examples
Parameters
...tasks: CallbackThreadGenerator[]
A list of tasks to run.
delay
public delaytime: numbertask: CallbackThreadGenerator: ThreadGenerator
Run the given generator or callback after a specific amount of time.
Examples
Parameters
time: number
The delay in seconds
task: CallbackThreadGenerator
The task or callback to run after the delay.
every
public everyinterval: numbercallback: EveryCallback: EveryTimer
Call the given callback every N seconds.
Examples
Parameters
interval: number
The interval between subsequent calls.
callback: EveryCallback
The callback to be called.
loop
public loopfactory: LoopCallback: ThreadGenerator
public loopiterations: numberfactory: LoopCallback: ThreadGenerator
Run the given generator in a loop.
Each iteration waits until the previous one is completed.
Because this loop never finishes it cannot be used in the main thread.
Instead, use yield
or spawn
to run the loop concurrently.
Examples
Parameters
factory: LoopCallback
A function creating the generator to run. Because generators can't be reset, a new generator is created on each iteration.
loopFor
public loopForseconds: numberfactory: LoopCallback: ThreadGenerator
Run a generator in a loop for the given amount of time.
Generators are executed completely before the next iteration starts. An iteration is allowed to finish even when the time is up. This means that the actual duration of the loop may be longer than the given duration.
Examples
Parameters
seconds: number
The duration in seconds.
factory: LoopCallback
A function creating the generator to run. Because generators can't be reset, a new generator is created on each iteration.
loopUntil
public loopUntilevent: stringfactory: LoopCallback: ThreadGenerator
Run a generator in a loop until the given time event.
Generators are executed completely before the next iteration starts. An iteration is allowed to finish even when the time is up. This means that the actual duration of the loop may be longer than the given duration.
Examples
Parameters
event: string
The event.
factory: LoopCallback
A function creating the generator to run. Because generators can't be reset, a new generator is created on each iteration.
noop
public noop(): ThreadGenerator
Do nothing.
run
public runrunner: () => ThreadGenerator: ThreadGenerator
public runname: stringrunner: () => ThreadGenerator: ThreadGenerator
Turn the given generator function into a task.
If you want to immediately run the generator in its own thread, you can use
spawn
instead. This function is useful when you want to
pass the created task to other flow functions.
Examples
Parameters
runner: () => ThreadGenerator
A generator function or a factory that creates the generator.
sequence
public sequencedelay: number...tasks: ThreadGenerator[]: ThreadGenerator
Start all tasks one after another with a constant delay between.
The function doesn't wait until the previous task in the sequence has finished. Once the delay has passed, the next task will start even if the previous is still running.
Examples
Parameters
delay: number
The delay between each of the tasks.
...tasks: ThreadGenerator[]
A list of tasks to be run in a sequence.
waitFor
public waitForseconds: number = 0after?: ThreadGenerator: ThreadGenerator
Wait for the given amount of time.
Examples
Parameters
seconds: number = 0
The relative time in seconds.
after?: ThreadGenerator
An optional task to be run after the function completes.
waitUntil
public waitUntilevent: stringafter?: ThreadGenerator: ThreadGenerator
Wait until the given time event.
Time events are displayed on the timeline and can be edited to adjust the delay. By default, an event happens immediately - without any delay.
Examples
Parameters
event: string
The name of the time event.
after?: ThreadGenerator
An optional task to be run after the function completes.