API reference › @evolu/common › Task › createGate
function createGate<D>(): Gate<D>;
Defined in: packages/common/src/Task.ts:2331
Creates a Gate that starts closed.
Useful for "stop/go" logic where multiple Tasks need to wait for a state change.
Example
const networkGate = createGate();
// Pause processing when offline
const onOffline = () => networkGate.close();
// Resume processing when online
const onOnline = () => networkGate.open();
const syncLoop = async (run) => {
while (true) {
// Blocks here whenever the gate is closed
await run(networkGate.wait);
await run(uploadNextItem);
}
};