Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/homecodeorg/timen
https://github.com/homecodeorg/timen
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/homecodeorg/timen
- Owner: homecodeorg
- Created: 2020-05-02T19:52:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-24T19:30:09.000Z (over 2 years ago)
- Last Synced: 2024-10-31T19:46:25.167Z (14 days ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[![npm](https://img.shields.io/npm/dm/timen?style=flat-square)](https://www.npmjs.com/package/timen)
Time Manager
====
Simple time manager based on `requestAnimationFrame`.## Installation
`yarn add timen` or `npm i timen`
## Usage
```js
import Time from 'timen';// Create time scope
const timers = Time.create();
const now = new Date();const sayHello = () => console.log('hello');
// Subscribe at time
timers.at(now.setMinutes(now.getMinutes() + 1), sayHello);// Subscribe at "after N ms" (same as setTimeout)
timers.after(1000, sayHello);// Subscribe at "every N ms" (same as setInterval)
timers.every(1000, sayHello);// Subscribe at "next tick"
timers.nextTick(sayHello);// Subscribe at "every next tick"
const unsubscribeIt = timers.tick(sayHello);
// Unsubscribe certain callback
unsubscribeIt();// Unsubscribe specifyed callback
timers.clear(sayHello);// Clear all timers in scope
timers.clear();
```