@@ -2,7 +2,66 @@ function unimplemented(name) {
2
2
throw new Error ( 'Node.js process ' + name + ' is not supported by JSPM core outside of Node.js' ) ;
3
3
}
4
4
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
+
6
65
var title = 'browser' ;
7
66
var arch = 'x64' ;
8
67
var platform = 'browser' ;
0 commit comments