Sleep
Using JS’s await feature, you can essentially pause execution of your code using ixfx’s Flow.sleep. This can make for very readable code and useful if you want to intersperse code with delays.
import { sleep } from "https://unpkg.com/ixfx/dist/flow.js"console.log(`Hello`);await sleep(1000);console.log(`There`); // Prints one second afterThere are a few tricks to using the await keyword. You may need to declare your function as being asynchronous:
const something = async () => { console.log(`Hello`); await sleep(1000); console.log(`There`); // Print one second after};
// Call the asynchronous functionsomething();// Execution will continue immediately, but execution within `something` will pause as expected.An alternative is delay, which takes a function to execute after some elapsed time.