Skip to main content

flow

                            
                              
                                import
                                
                                {
                                ...
                                }
                                
                                from
                                
                                "@motion-canvas/core/lib/flow"
                                ;
                                

Utilities for controlling the flow and timing of an animation.

Interfaces

  • EveryCallback
  • EveryTimer
  • LoopCallback

Functions

all

                            
                              
                                public 
                                all
                                
                                  
                                    
                                      ...
                                      tasks
                                      : 
                                      ThreadGenerator
                                      []
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Run all tasks concurrently and wait for all of them to finish.

Examples

Parameters


any

                            
                              
                                public 
                                any
                                
                                  
                                    
                                      ...
                                      tasks
                                      : 
                                      ThreadGenerator
                                      []
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Run all tasks concurrently and wait for any of them to finish.

Examples

Parameters


chain

                            
                              
                                public 
                                chain
                                
                                  
                                    
                                      ...
                                      tasks
                                      : 
                                      
                                        
                                          
                                            ThreadGenerator
                                          
                                          
                                            Callback
                                          
                                        
                                      
                                      []
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Run tasks one after another.

Examples

Parameters


delay

                            
                              
                                public 
                                delay
                                
                                  
                                    
                                      time
                                      : 
                                      number
                                    
                                    
                                      task
                                      : 
                                      
                                        
                                          
                                            ThreadGenerator
                                          
                                          
                                            Callback
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Run the given generator or callback after a specific amount of time.

Examples

Parameters


every

                            
                              
                                public 
                                every
                                
                                  
                                    
                                      interval
                                      : 
                                      number
                                    
                                    
                                      callback
                                      : 
                                      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 
                                loop
                                
                                  
                                    
                                      iterations
                                      : 
                                      number
                                    
                                    
                                      factory
                                      : 
                                      LoopCallback
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Run the given generator N times.

Each time iteration waits until the previous one is completed.

Examples

Parameters

  • iterations : number

    The number of iterations.

  • factory : LoopCallback

    A function creating the generator to run. Because generatorscan't be reset, a new generator is created on each iteration.


noop

                            
                              
                                public 
                                noop
                                (): 
                                ThreadGenerator
                              
                              

Do nothing.


run

                            
                              
                                public 
                                run
                                
                                  
                                    
                                      runner
                                      : 
                                      public 
                                      
                                      ()
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              
                            
                              
                                public 
                                run
                                
                                  
                                    
                                      name
                                      : 
                                      string
                                    
                                    
                                      runner
                                      : 
                                      public 
                                      
                                      ()
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Turn the given generator function into a threadable generator.

Examples

Parameters

  • runner : public ()

    A generator function or a factory that creates the generator.


sequence

                            
                              
                                public 
                                sequence
                                
                                  
                                    
                                      delay
                                      : 
                                      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 hasfinished. Once the delay has passed, the next task will start even ifthe 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 
                                waitFor
                                
                                  
                                    
                                      seconds
                                      : 
                                      number
                                       = 
                                      0
                                    
                                    
                                      after
                                      ?: 
                                      ThreadGenerator
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Wait for the given amount of time.

Examples

Parameters


waitUntil

                            
                              
                                public 
                                waitUntil
                                
                                  
                                    
                                      event
                                      : 
                                      string
                                    
                                    
                                      after
                                      ?: 
                                      ThreadGenerator
                                    
                                  
                                
                                : 
                                ThreadGenerator
                              
                              

Wait until the given time event.

Time events are displayed on the timeline and can be edited to adjust thedelay. 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.