Skip to content

Commit 00bdb7e

Browse files
committed
2.0.0-beta.10
1 parent bbfbdb7 commit 00bdb7e

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

nodelibs/browser/process.js

+60-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,66 @@ function unimplemented(name) {
22
throw new Error('Node.js process ' + name + ' is not supported by JSPM core outside of Node.js');
33
}
44

5-
var nextTick = cb => Promise.resolve().then(cb);
5+
var queue = [];
6+
var draining = false;
7+
var currentQueue;
8+
var queueIndex = -1;
9+
10+
function cleanUpNextTick() {
11+
if (!draining || !currentQueue)
12+
return;
13+
draining = false;
14+
if (currentQueue.length) {
15+
queue = currentQueue.concat(queue);
16+
}
17+
else {
18+
queueIndex = -1;
19+
}
20+
if (queue.length)
21+
drainQueue();
22+
}
23+
24+
function drainQueue() {
25+
if (draining)
26+
return;
27+
var timeout = setTimeout(cleanUpNextTick, 0);
28+
draining = true;
29+
30+
var len = queue.length;
31+
while(len) {
32+
currentQueue = queue;
33+
queue = [];
34+
while (++queueIndex < len) {
35+
if (currentQueue)
36+
currentQueue[queueIndex].run();
37+
}
38+
queueIndex = -1;
39+
len = queue.length;
40+
}
41+
currentQueue = null;
42+
draining = false;
43+
clearTimeout(timeout);
44+
}
45+
46+
function nextTick (fun) {
47+
var args = new Array(arguments.length - 1);
48+
if (arguments.length > 1) {
49+
for (var i = 1; i < arguments.length; i++)
50+
args[i - 1] = arguments[i];
51+
}
52+
queue.push(new Item(fun, args));
53+
if (queue.length === 1 && !draining)
54+
setTimeout(drainQueue, 0);
55+
}
56+
// v8 likes predictible objects
57+
function Item(fun, array) {
58+
this.fun = fun;
59+
this.array = array;
60+
}
61+
Item.prototype.run = function () {
62+
this.fun.apply(null, this.array);
63+
};
64+
665
var title = 'browser';
766
var arch = 'x64';
867
var platform = 'browser';

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jspm/core",
3-
"version": "2.0.0-beta.9",
3+
"version": "2.0.0-beta.10",
44
"scripts": {
55
"build": "rollup -c",
66
"generate:node": "node generate-node-libs.mjs",

0 commit comments

Comments
 (0)