mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-16 08:15:55 +10:00
90 lines
5.8 KiB
JSON
90 lines
5.8 KiB
JSON
{
|
|
"name": "setimmediate",
|
|
"description": "A shim for the setImmediate efficient script yielding API",
|
|
"version": "1.0.1",
|
|
"author": {
|
|
"name": "NobleJS"
|
|
},
|
|
"contributors": [
|
|
{
|
|
"name": "Domenic Denicola",
|
|
"email": "domenic@domenicdenicola.com",
|
|
"url": "http://domenicdenicola.com"
|
|
},
|
|
{
|
|
"name": "Donavon West"
|
|
},
|
|
{
|
|
"name": "Yaffle"
|
|
}
|
|
],
|
|
"license": "MIT",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git://github.com/NobleJS/setImmediate.git"
|
|
},
|
|
"bugs": {
|
|
"url": "http://github.com/NobleJS/setImmediate/issues"
|
|
},
|
|
"main": "setImmediate.js",
|
|
"scripts": {
|
|
"lint": "jshint setImmediate.js",
|
|
"test": "mocha test/tests.js",
|
|
"test-browser": "opener http://localhost:9000 && zuul --server 9000 test/tests.js --wwwroot test/",
|
|
"test-browser-only": "opener http://localhost:9007/test/browserOnly/index.html && http-server . -p 9007"
|
|
},
|
|
"devDependencies": {
|
|
"jshint": ">= 0.9.1",
|
|
"mocha": ">= 1.7.4",
|
|
"zuul": ">= 0.0.1",
|
|
"http-server": ">= 0.5.3",
|
|
"opener": ">= 1.1.0"
|
|
},
|
|
"testling": {
|
|
"browsers": {
|
|
"ie": [
|
|
6,
|
|
7,
|
|
8,
|
|
9
|
|
],
|
|
"chrome": [
|
|
4,
|
|
23,
|
|
"canary"
|
|
],
|
|
"firefox": [
|
|
3,
|
|
3.5,
|
|
3.6,
|
|
4,
|
|
17,
|
|
"nightly"
|
|
],
|
|
"opera": [
|
|
10,
|
|
10.5,
|
|
11,
|
|
11.5,
|
|
11.6,
|
|
12,
|
|
"next"
|
|
],
|
|
"safari": [
|
|
"5.0.5",
|
|
5.1
|
|
]
|
|
},
|
|
"harness": "mocha",
|
|
"files": "test/tests.js"
|
|
},
|
|
"readme": "<a href=\"http://ci.testling.com/NobleJS/setImmediate\">\n <img src=\"http://ci.testling.com/NobleJS/setImmediate.png\" alt=\"Testling-CI badge showing browser compliance\"\n align=\"right\">\n</a>\n\n# setImmediate.js\n**A NobleJS production**\n\n## Introduction\n\n**setImmediate.js** is a highly cross-browser implementation of the `setImmediate` and `clearImmediate` APIs, currently\na [W3C draft spec][spec] from the Web Performance Working Group. `setImmediate` allows scripts to yield to the browser,\nexecuting a given operation asynchronously, in a manner that is typically more efficient and consumes less power than\nthe usual `setTimeout(..., 0)` pattern.\n\nsetImmediate.js runs at “full speed” in the following browsers and environments, using various clever tricks:\n\n * Internet Explorer 6+\n * Firefox 3+\n * WebKit\n * Opera 9.5+\n * Node.js\n * Web workers in browsers that support `MessageChannel`, which I can't find solid info on.\n\nIn all other browsers we fall back to using `setTimeout`, so it's always safe to use.\n\n## The Tricks\n\n### `process.nextTick`\n\nIn Node.js versions below 0.9, `setImmediate` is not available, but [`process.nextTick`][nextTIck] is, so we use it to\nshim support for a global `setImmediate`. In Node.js 0.9 and above, `setImmediate` is available.\n\nNote that we check for *actual* Node.js environments, not emulated ones like those produced by browserify or similar.\nSuch emulated environments often already include a `process.nextTick` shim that's not as browser-compatible as\nsetImmediate.js.\n\n### `postMessage`\n\nIn Firefox 3+, Internet Explorer 9+, all modern WebKit browsers, and Opera 9.5+, [`postMessage`][postMessage] is\navailable and provides a good way to queue tasks on the event loop. It's quite the abuse, using a cross-document\nmessaging protocol within the same document simply to get access to the event loop task queue, but until there are\nnative implementations, this is the best option.\n\nNote that Internet Explorer 8 includes a synchronous version of `postMessage`. We detect this, or any other such\nsynchronous implementation, and fall back to another trick.\n\n### `MessageChannel`\n\nUnfortunately, `postMessage` has completely different semantics inside web workers, and so cannot be used there. So we\nturn to [`MessageChannel`][MessageChannel], which has worse browser support, but does work inside a web worker.\n\n### `<script> onreadystatechange`\n\nFor our last trick, we pull something out to make things fast in Internet Explorer versions 6 through 8: namely,\ncreating a `<script>` element and firing our calls in its `onreadystatechange` event. This does execute in a future\nturn of the event loop, and is also faster than `setTimeout(…, 0)`, so hey, why not?\n\n## Usage\n\nIn the browser, include it with a `<script>` tag; pretty simple.\n\nIn Node.js, do\n\n```\nnpm install setimmediate\n```\n\nthen\n\n```js\nrequire(\"setimmediate\");\n```\n\nsomewhere early in your app; it attaches to the global.\n\n## Demo\n\n* [Quick sort demo][cross-browser-demo]\n \n## Reference and Reading\n\n * [Efficient Script Yielding W3C Editor's Draft][spec]\n * [W3C mailing list post introducing the specification][list-post]\n * [IE Test Drive demo][ie-demo]\n * [Introductory blog post by Nicholas C. Zakas][ncz]\n\n\n[spec]: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/setImmediate/Overview.html\n[list-post]: http://lists.w3.org/Archives/Public/public-web-perf/2011Jun/0100.html\n[ie-demo]: http://ie.microsoft.com/testdrive/Performance/setImmediateSorting/Default.html\n[ncz]: http://www.nczonline.net/blog/2011/09/19/script-yielding-with-setimmediate/\n[nextTick]: http://nodejs.org/docs/v0.8.16/api/process.html#process_process_nexttick_callback\n[postMessage]: http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#posting-messages\n[MessageChannel]: http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#channel-messaging\n[cross-browser-demo]: http://jphpsf.github.com/setImmediate-shim-demo\n",
|
|
"readmeFilename": "README.md",
|
|
"_id": "setimmediate@1.0.1",
|
|
"dist": {
|
|
"shasum": "5d02328af646f1ba3d0e7dcf275f6714c69d8ae8"
|
|
},
|
|
"_from": "setimmediate@1.0.1",
|
|
"_resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.1.tgz"
|
|
}
|