UNPKG

quicktask

Version:

Tiny microtask queue scheduler for all environments

36 lines 2.08 kB
{ "name": "quicktask", "version": "1.2.0", "description": "Tiny microtask queue scheduler for all environments", "main": "index.js", "files": [ "index.d.ts", "index.js", "index.js.map" ], "repository": { "type": "git", "url": "git+ssh://git@github.com/staltz/quicktask.git" }, "keywords": [ "microtask", "nanotask", "schedule" ], "author": "staltz.com", "license": "MIT", "bugs": { "url": "https://github.com/staltz/quicktask/issues" }, "homepage": "https://github.com/staltz/quicktask", "devDependencies": { "typescript": "4.5.x", "@types/node": "14.x" }, "scripts": { "compile": "tsc", "test": "tsc", "prepublish": "npm run compile" }, "readme": "# Quicktask\n\n> Tiny microtask queue scheduler for all environments\n\n```bash\nnpm install --save quicktask\n```\n\nInspired by `yoshuawuyts/nanotask`, this function manages a queue of microtasks, but focuses on being cross environment (not just browser) and with a tiny implementation. It returns a \"scheduleMicrotask\" helper.\n\n- Uses `queueMicrotask` if available\n- Otherwise uses `setImmediate` if available.\n- Otherwise uses `process.nextTick` in Node.js.\n- Otherwise uses `setTimeout` otherwise.\n\n**Unless you need to support old runtimes or Internet Explorer, we recommend using `queueMicrotask` directly**. That said, this library is less than 1kB in size.\n\n## Usage\n\nIn JavaScript / Node.js:\n\n```js\nconst quicktask = require('quicktask').default;\nconst schedule = quicktask();\n\nschedule(function () {\n console.log('resolved at the start of the next frame');\n});\n```\n\nIn TypeScript:\n\n```typescript\nimport quicktask from 'quicktask';\nconst schedule = quicktask();\n\nschedule(() => {\n console.log('resolved at the start of the next frame');\n});\n```\n\n## API\n\n### `const schedule = quicktask()`\n\nCreate a new Quicktask instance.\n\n### `schedule(fn)`\n\nQueue a function to run before the end of the current event loop.\n\n## License\n\n[MIT](https://tldrlegal.com/license/mit-license)\n" }