{"id":19181381,"url":"https://github.com/uid11/next-task","last_synced_at":"2026-06-18T22:31:18.623Z","repository":{"id":138022524,"uuid":"67464982","full_name":"uid11/next-task","owner":"uid11","description":"Implementation of nextTick (microtask queue) for all platforms (like asap.js)","archived":false,"fork":false,"pushed_at":"2016-09-19T16:52:21.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-26T02:58:52.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uid11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-09-06T02:09:04.000Z","updated_at":"2016-11-18T09:27:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c034c9a-355a-4936-b8ae-5986e82b6af9","html_url":"https://github.com/uid11/next-task","commit_stats":null,"previous_names":["uid-11222/next-task"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/uid11/next-task","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fnext-task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fnext-task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fnext-task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fnext-task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uid11","download_url":"https://codeload.github.com/uid11/next-task/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fnext-task/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34510281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T10:53:13.311Z","updated_at":"2026-06-18T22:31:18.598Z","avatar_url":"https://github.com/uid11.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-task #\n\n[![NPM version][npm-image]][npm-url] ![dependencies][dependencies-image] [![License MIT][license-image]](LICENSE)\n\n[![NPM](https://nodei.co/npm/next-task.png)](https://nodei.co/npm/next-task/)\n\nFast microtask queue for all platforms, equivalent rawAsap (based on the ideas and source of rawAsap), but a little faster.\n\n## Usage ##\n```js\nvar nextTask = require('next-task');\n\nnextTask(function() {\n  /* this === undefined, arguments.length === 0 */\n  console.log('Run this async, but \"as soon as possible\".');\n});\n\nconsole.log('This run sync.');\n\n/** Log:\n * -\u003e This run sync.\n * -\u003e Run this async, but \"as soon as possible\".\n */\n\n/** Variant with context: */\nvar task = {\n    data: ...,\n    call: function() {/* this === task */}\n};\n\nnextTask(task);\n```\nAbout rawAsap and microtasks: [rawAsap](https://github.com/kriskowal/asap#raw-asap).\nIf you need queue of animation tasks, use [raf](https://github.com/chrisdickinson/raf) instead, for synchronize with rendering loop.\nIf you need to perform a long (macrotask) queue of heavy tasks, use [setImmediate](https://github.com/YuzuJS/setImmediate) to give the browser the ability to handle current events.\nNote that, like rawAsap, **next-task** does not catch the errors (to work as soon as possible).\n\n\n## Differences from rawAsap ##\n\n### Errors ###\n```js\n/**\n * If a task does throw an error, with rawAsap you need\n * call requestFlush (after error):\n */\nrawAsap.requestFlush();\n\n/**\n * With nextTask just call it without arguments\n *(or with null or undefined), also after error:\n */\nnextTask();\n```\n\n### Domains ###\n**next-task** does not support domains for Node.js (rasAsap does).\n\n### Promise ###\n**next-task** uses native Promise, if it is available (only native, and ignores any polyfills). More information: [Consider using Promise.prototype.then](https://github.com/kriskowal/asap/issues/54).\n\n### Property 'use' ###\nProperty 'use' points to the technology used:\n```js\n/** In the order of attempts to use: */\nnextTask.use === 'setImmediate'     || /* only Node.js */\n                 'Promise'          || /* ES6 native promise, if available */\n                 'MutationObserver' || /* modern browsers */\n                 'setTimeout'          /* all other platforms */\n```\n\n### Method 'setCapacity' ###\nMethod 'setCapacity' limited the memory usage (more information: [function to change rawAsap.capacity value must be added](https://github.com/kriskowal/asap/issues/53)):\n```js\nnextTask.setCapacity(1024); /* return 1024 */\n\nnextTask.setCapacity(); /* return 1024 */\nnextTask.setCapacity({}); /* return 1024 */\n\nnextTask.setCapacity(100); /* return 100 */\n```\n\n## Build ##\nInstall all the packages from devDependencies in ./node_modules and run build:\n```bash\n$ npm install\n$ npm run build\n```\nThen you will be able to perform tests and benchmark.\n\n## Benchmarks ##\n```bash\n$ npm run benchmark:node\n$ npm run benchmark:browser\n```\nThis is benchmark from [asap/benchmarks](https://github.com/kriskowal/asap/tree/master/benchmarks), in which different ways queuing added for comparison.\nThe results are not very stable and not fully explained; for example, a typical result in Node.js:\n```bash\nasap x 5,584 ops/sec ±3.90% (56 runs sampled)\nrawAsap x 39,700 ops/sec ±7.41% (56 runs sampled)\nnextTask x 41,186 ops/sec ±7.55% (57 runs sampled)\nnextTick x 11,711 ops/sec ±5.81% (58 runs sampled)\nnextTick[] x 23,823 ops/sec ±3.49% (59 runs sampled)\nsetImmediate x 5,860 ops/sec ±4.92% (59 runs sampled)\nsetImmediate[] x 14,182 ops/sec ±3.91% (59 runs sampled)\nPromise x 811 ops/sec ±3.43% (58 runs sampled)\nPromise[] x 11,993 ops/sec ±1.89% (55 runs sampled)\nsetTimeout x 612 ops/sec ±1.95% (59 runs sampled)\nsetTimeout[] x 768 ops/sec ±1.32% (58 runs sampled)\n```\n\nThe results of benchmark in DOM even more dependent on the browser.\nFor example, in modern Chrome:\n```bash\nasap x 6,770 ops/sec ±4.53% (42 runs sampled)\nrawAsap x 27,173 ops/sec ±7.02% (42 runs sampled)\nnextTask x 32,403 ops/sec ±3.36% (46 runs sampled)\nPromise x 891 ops/sec ±3.33% (44 runs sampled)\nPromise[] x 10,534 ops/sec ±2.21% (42 runs sampled)\nMutationObserver[] x 4,792 ops/sec ±5.05% (41 runs sampled)\nsetTimeout x 115 ops/sec ±1.56% (47 runs sampled)\nsetTimeout[] x 226 ops/sec ±1.85% (50 runs sampled)\n```\n\nThere \"Promise\" is run each task by Promise and \"Promise[]\" means the use of the task queue, so that the whole queue is run with one call Promise; and similarly for the other methods.\n\n## Tests ##\n```bash\n$ npm run test:node\n$ npm run test:browser\n```\n\n## License ##\n[MIT](LICENSE)\n\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg \"license-image\"\n[dependencies-image]: https://img.shields.io/gemnasium/mathiasbynens/he.svg?maxAge=2592000 \"dependencies-image\"\n[npm-image]: https://img.shields.io/npm/v/next-task.svg \"npm-image\"\n[npm-url]: https://www.npmjs.com/package/next-task \"next-task\"","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuid11%2Fnext-task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuid11%2Fnext-task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuid11%2Fnext-task/lists"}