https://github.com/onthegosystems/smart_delay
https://github.com/onthegosystems/smart_delay
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/onthegosystems/smart_delay
- Owner: OnTheGoSystems
- Created: 2019-04-22T08:35:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-22T10:03:22.000Z (about 7 years ago)
- Last Synced: 2025-11-18T05:03:58.281Z (7 months ago)
- Language: JavaScript
- Size: 44.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SmartDelay
## Simple library for delaying operations
When you need to ensure execution of some operation only once per interval just call a single method and don't care about intervals and timeouts.
# Usage example
```js
import { SmartDelay } from "@tarvit/smart_delay";
// Use as function
const id = "your-context-id-here"; // create an id for your action (so you can execute same actions in different contexts)
const timeout = 100; // set your delay
const action = ()=> { console.log('exec something') }; // define your action
SmartDelay.executeDelayedAction(id, action, timeout); // fire delayed action, it will be executed 100ms later if not another fire. it will be delayed every time your fire it and can be executed only once per 100ms.
// Use as worker
const worker = SmartDelay.get(`your-dynamic-id`, ()=> {
console.log('perform your operation')
});
worker.executeDelayed(); // call this to fire a delayed action
worker.isDone(); // check if it is done
worker.isWaiting(); // check if it is in progress
worker.release(); // stop actions
```