Installation
npm install @turtlemay/routines
Basic Usage
Import or require the RoutineManager class:
import {RoutineManager} from '@turtlemay/routines';
const RoutineManager = require('@turtlemay/routines').RoutineManager;
Create a RoutineManager:
const co = new RoutineManager();
Update the RoutineManager: (e.g. during your main loop)
co.updateAll();
Define routines as generators:
function* myRoutine() {
while (true) {
console.log('Hello routine.');
yield;
}
}
Start a routine:
co.start(myRoutine());
Waiting
Wait for another routine:
function* myRoutine2() {
console.log('Waiting for other routine...');
yield* myRoutine();
console.log('Other routine finished.');
}
Wait for an amount of time:
import {waitForSeconds} from '@turtlemay/routines';
function* myRoutine() {
console.log('Waiting for 1 second...');
yield* waitForSeconds(1);
console.log('Done...');
}