1 | !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var unhandledRejections = require('../lib/decorators/unhandledRejection');
|
10 | var PromiseConstructor = unhandledRejections(require('../lib/Promise'));
|
11 |
|
12 | module.exports = typeof global != 'undefined' ? (global.Promise = PromiseConstructor)
|
13 | : typeof self != 'undefined' ? (self.Promise = PromiseConstructor)
|
14 | : PromiseConstructor;
|
15 |
|
16 | },{"../lib/Promise":2,"../lib/decorators/unhandledRejection":6}],2:[function(require,module,exports){
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | (function(define) { 'use strict';
|
22 | define(function (require) {
|
23 |
|
24 | var makePromise = require('./makePromise');
|
25 | var Scheduler = require('./Scheduler');
|
26 | var async = require('./async');
|
27 |
|
28 | return makePromise({
|
29 | scheduler: new Scheduler(async)
|
30 | });
|
31 |
|
32 | });
|
33 | })(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); });
|
34 |
|
35 | },{"./Scheduler":4,"./async":5,"./makePromise":7}],3:[function(require,module,exports){
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | (function(define) { 'use strict';
|
41 | define(function() {
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | function Queue(capacityPow2) {
|
50 | this.head = this.tail = this.length = 0;
|
51 | this.buffer = new Array(1 << capacityPow2);
|
52 | }
|
53 |
|
54 | Queue.prototype.push = function(x) {
|
55 | if(this.length === this.buffer.length) {
|
56 | this._ensureCapacity(this.length * 2);
|
57 | }
|
58 |
|
59 | this.buffer[this.tail] = x;
|
60 | this.tail = (this.tail + 1) & (this.buffer.length - 1);
|
61 | ++this.length;
|
62 | return this.length;
|
63 | };
|
64 |
|
65 | Queue.prototype.shift = function() {
|
66 | var x = this.buffer[this.head];
|
67 | this.buffer[this.head] = void 0;
|
68 | this.head = (this.head + 1) & (this.buffer.length - 1);
|
69 | --this.length;
|
70 | return x;
|
71 | };
|
72 |
|
73 | Queue.prototype._ensureCapacity = function(capacity) {
|
74 | var head = this.head;
|
75 | var buffer = this.buffer;
|
76 | var newBuffer = new Array(capacity);
|
77 | var i = 0;
|
78 | var len;
|
79 |
|
80 | if(head === 0) {
|
81 | len = this.length;
|
82 | for(; i<len; ++i) {
|
83 | newBuffer[i] = buffer[i];
|
84 | }
|
85 | } else {
|
86 | capacity = buffer.length;
|
87 | len = this.tail;
|
88 | for(; head<capacity; ++i, ++head) {
|
89 | newBuffer[i] = buffer[head];
|
90 | }
|
91 |
|
92 | for(head=0; head<len; ++i, ++head) {
|
93 | newBuffer[i] = buffer[head];
|
94 | }
|
95 | }
|
96 |
|
97 | this.buffer = newBuffer;
|
98 | this.head = 0;
|
99 | this.tail = this.length;
|
100 | };
|
101 |
|
102 | return Queue;
|
103 |
|
104 | });
|
105 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
106 |
|
107 | },{}],4:[function(require,module,exports){
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | (function(define) { 'use strict';
|
113 | define(function(require) {
|
114 |
|
115 | var Queue = require('./Queue');
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 | function Scheduler(async) {
|
126 | this._async = async;
|
127 | this._queue = new Queue(15);
|
128 | this._afterQueue = new Queue(5);
|
129 | this._running = false;
|
130 |
|
131 | var self = this;
|
132 | this.drain = function() {
|
133 | self._drain();
|
134 | };
|
135 | }
|
136 |
|
137 | |
138 |
|
139 |
|
140 |
|
141 | Scheduler.prototype.enqueue = function(task) {
|
142 | this._add(this._queue, task);
|
143 | };
|
144 |
|
145 | |
146 |
|
147 |
|
148 |
|
149 | Scheduler.prototype.afterQueue = function(task) {
|
150 | this._add(this._afterQueue, task);
|
151 | };
|
152 |
|
153 | |
154 |
|
155 |
|
156 | Scheduler.prototype._drain = function() {
|
157 | runQueue(this._queue);
|
158 | this._running = false;
|
159 | runQueue(this._afterQueue);
|
160 | };
|
161 |
|
162 | |
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | Scheduler.prototype._add = function(queue, task) {
|
169 | queue.push(task);
|
170 | if(!this._running) {
|
171 | this._running = true;
|
172 | this._async(this.drain);
|
173 | }
|
174 | };
|
175 |
|
176 | |
177 |
|
178 |
|
179 |
|
180 | function runQueue(queue) {
|
181 | while(queue.length > 0) {
|
182 | queue.shift().run();
|
183 | }
|
184 | }
|
185 |
|
186 | return Scheduler;
|
187 |
|
188 | });
|
189 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
190 |
|
191 | },{"./Queue":3}],5:[function(require,module,exports){
|
192 |
|
193 |
|
194 |
|
195 |
|
196 | (function(define) { 'use strict';
|
197 | define(function(require) {
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | var nextTick, MutationObs;
|
206 |
|
207 | if (typeof process !== 'undefined' && process !== null &&
|
208 | typeof process.nextTick === 'function') {
|
209 | nextTick = function(f) {
|
210 | process.nextTick(f);
|
211 | };
|
212 |
|
213 | } else if (MutationObs =
|
214 | (typeof MutationObserver === 'function' && MutationObserver) ||
|
215 | (typeof WebKitMutationObserver === 'function' && WebKitMutationObserver)) {
|
216 | nextTick = (function (document, MutationObserver) {
|
217 | var scheduled;
|
218 | var el = document.createElement('div');
|
219 | var o = new MutationObserver(run);
|
220 | o.observe(el, { attributes: true });
|
221 |
|
222 | function run() {
|
223 | var f = scheduled;
|
224 | scheduled = void 0;
|
225 | f();
|
226 | }
|
227 |
|
228 | return function (f) {
|
229 | scheduled = f;
|
230 | el.setAttribute('class', 'x');
|
231 | };
|
232 | }(document, MutationObs));
|
233 |
|
234 | } else {
|
235 | nextTick = (function(cjsRequire) {
|
236 | try {
|
237 |
|
238 | return cjsRequire('vertx').runOnLoop || cjsRequire('vertx').runOnContext;
|
239 | } catch (ignore) {}
|
240 |
|
241 |
|
242 |
|
243 | var capturedSetTimeout = setTimeout;
|
244 | return function (t) {
|
245 | capturedSetTimeout(t, 0);
|
246 | };
|
247 | }(require));
|
248 | }
|
249 |
|
250 | return nextTick;
|
251 | });
|
252 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
253 |
|
254 | },{}],6:[function(require,module,exports){
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | (function(define) { 'use strict';
|
260 | define(function(require) {
|
261 |
|
262 | var timer = require('../timer');
|
263 |
|
264 | return function unhandledRejection(Promise) {
|
265 | var logError = noop;
|
266 | var logInfo = noop;
|
267 |
|
268 | if(typeof console !== 'undefined') {
|
269 | logError = typeof console.error !== 'undefined'
|
270 | ? function (e) { console.error(e); }
|
271 | : function (e) { console.log(e); };
|
272 |
|
273 | logInfo = typeof console.info !== 'undefined'
|
274 | ? function (e) { console.info(e); }
|
275 | : function (e) { console.log(e); };
|
276 | }
|
277 |
|
278 | Promise.onPotentiallyUnhandledRejection = function(rejection) {
|
279 | enqueue(report, rejection);
|
280 | };
|
281 |
|
282 | Promise.onPotentiallyUnhandledRejectionHandled = function(rejection) {
|
283 | enqueue(unreport, rejection);
|
284 | };
|
285 |
|
286 | Promise.onFatalRejection = function(rejection) {
|
287 | enqueue(throwit, rejection.value);
|
288 | };
|
289 |
|
290 | var tasks = [];
|
291 | var reported = [];
|
292 | var running = false;
|
293 |
|
294 | function report(r) {
|
295 | if(!r.handled) {
|
296 | reported.push(r);
|
297 | logError('Potentially unhandled rejection [' + r.id + '] ' + formatError(r.value));
|
298 | }
|
299 | }
|
300 |
|
301 | function unreport(r) {
|
302 | var i = reported.indexOf(r);
|
303 | if(i >= 0) {
|
304 | reported.splice(i, 1);
|
305 | logInfo('Handled previous rejection [' + r.id + '] ' + formatObject(r.value));
|
306 | }
|
307 | }
|
308 |
|
309 | function enqueue(f, x) {
|
310 | tasks.push(f, x);
|
311 | if(!running) {
|
312 | running = true;
|
313 | running = timer.set(flush, 0);
|
314 | }
|
315 | }
|
316 |
|
317 | function flush() {
|
318 | running = false;
|
319 | while(tasks.length > 0) {
|
320 | tasks.shift()(tasks.shift());
|
321 | }
|
322 | }
|
323 |
|
324 | return Promise;
|
325 | };
|
326 |
|
327 | function formatError(e) {
|
328 | var s = typeof e === 'object' && e.stack ? e.stack : formatObject(e);
|
329 | return e instanceof Error ? s : s + ' (WARNING: non-Error used)';
|
330 | }
|
331 |
|
332 | function formatObject(o) {
|
333 | var s = String(o);
|
334 | if(s === '[object Object]' && typeof JSON !== 'undefined') {
|
335 | s = tryStringify(o, s);
|
336 | }
|
337 | return s;
|
338 | }
|
339 |
|
340 | function tryStringify(e, defaultValue) {
|
341 | try {
|
342 | return JSON.stringify(e);
|
343 | } catch(e) {
|
344 |
|
345 | return defaultValue;
|
346 | }
|
347 | }
|
348 |
|
349 | function throwit(e) {
|
350 | throw e;
|
351 | }
|
352 |
|
353 | function noop() {}
|
354 |
|
355 | });
|
356 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
357 |
|
358 | },{"../timer":8}],7:[function(require,module,exports){
|
359 |
|
360 |
|
361 |
|
362 |
|
363 | (function(define) { 'use strict';
|
364 | define(function() {
|
365 |
|
366 | return function makePromise(environment) {
|
367 |
|
368 | var tasks = environment.scheduler;
|
369 |
|
370 | var objectCreate = Object.create ||
|
371 | function(proto) {
|
372 | function Child() {}
|
373 | Child.prototype = proto;
|
374 | return new Child();
|
375 | };
|
376 |
|
377 | |
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 | function Promise(resolver, handler) {
|
384 | this._handler = resolver === Handler ? handler : init(resolver);
|
385 | }
|
386 |
|
387 | |
388 |
|
389 |
|
390 |
|
391 |
|
392 | function init(resolver) {
|
393 | var handler = new Pending();
|
394 |
|
395 | try {
|
396 | resolver(promiseResolve, promiseReject, promiseNotify);
|
397 | } catch (e) {
|
398 | promiseReject(e);
|
399 | }
|
400 |
|
401 | return handler;
|
402 |
|
403 | |
404 |
|
405 |
|
406 |
|
407 |
|
408 | function promiseResolve (x) {
|
409 | handler.resolve(x);
|
410 | }
|
411 | |
412 |
|
413 |
|
414 |
|
415 |
|
416 | function promiseReject (reason) {
|
417 | handler.reject(reason);
|
418 | }
|
419 |
|
420 | |
421 |
|
422 |
|
423 |
|
424 | function promiseNotify (x) {
|
425 | handler.notify(x);
|
426 | }
|
427 | }
|
428 |
|
429 |
|
430 |
|
431 | Promise.resolve = resolve;
|
432 | Promise.reject = reject;
|
433 | Promise.never = never;
|
434 |
|
435 | Promise._defer = defer;
|
436 | Promise._handler = getHandler;
|
437 |
|
438 | |
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | function resolve(x) {
|
445 | return isPromise(x) ? x
|
446 | : new Promise(Handler, new Async(getHandler(x)));
|
447 | }
|
448 |
|
449 | |
450 |
|
451 |
|
452 |
|
453 |
|
454 | function reject(x) {
|
455 | return new Promise(Handler, new Async(new Rejected(x)));
|
456 | }
|
457 |
|
458 | |
459 |
|
460 |
|
461 |
|
462 | function never() {
|
463 | return foreverPendingPromise;
|
464 | }
|
465 |
|
466 | |
467 |
|
468 |
|
469 |
|
470 |
|
471 | function defer() {
|
472 | return new Promise(Handler, new Pending());
|
473 | }
|
474 |
|
475 |
|
476 |
|
477 | |
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 | Promise.prototype.then = function(onFulfilled, onRejected) {
|
488 | var parent = this._handler;
|
489 |
|
490 | if (typeof onFulfilled !== 'function' && parent.join().state() > 0) {
|
491 |
|
492 | return new Promise(Handler, parent);
|
493 | }
|
494 |
|
495 | var p = this._beget();
|
496 | var child = p._handler;
|
497 |
|
498 | parent.chain(child, parent.receiver, onFulfilled, onRejected,
|
499 | arguments.length > 2 ? arguments[2] : void 0);
|
500 |
|
501 | return p;
|
502 | };
|
503 |
|
504 | |
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 | Promise.prototype['catch'] = function(onRejected) {
|
511 | return this.then(void 0, onRejected);
|
512 | };
|
513 |
|
514 | |
515 |
|
516 |
|
517 |
|
518 |
|
519 | Promise.prototype._beget = function() {
|
520 | var parent = this._handler;
|
521 | var child = new Pending(parent.receiver, parent.join().context);
|
522 | return new this.constructor(Handler, child);
|
523 | };
|
524 |
|
525 |
|
526 |
|
527 | Promise.all = all;
|
528 | Promise.race = race;
|
529 |
|
530 | |
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 | function all(promises) {
|
538 |
|
539 | var resolver = new Pending();
|
540 | var pending = promises.length >>> 0;
|
541 | var results = new Array(pending);
|
542 |
|
543 | var i, h, x, s;
|
544 | for (i = 0; i < promises.length; ++i) {
|
545 | x = promises[i];
|
546 |
|
547 | if (x === void 0 && !(i in promises)) {
|
548 | --pending;
|
549 | continue;
|
550 | }
|
551 |
|
552 | if (maybeThenable(x)) {
|
553 | h = isPromise(x)
|
554 | ? x._handler.join()
|
555 | : getHandlerUntrusted(x);
|
556 |
|
557 | s = h.state();
|
558 | if (s === 0) {
|
559 | h.fold(settleAt, i, results, resolver);
|
560 | } else if (s > 0) {
|
561 | results[i] = h.value;
|
562 | --pending;
|
563 | } else {
|
564 | resolver.become(h);
|
565 | break;
|
566 | }
|
567 |
|
568 | } else {
|
569 | results[i] = x;
|
570 | --pending;
|
571 | }
|
572 | }
|
573 |
|
574 | if(pending === 0) {
|
575 | resolver.become(new Fulfilled(results));
|
576 | }
|
577 |
|
578 | return new Promise(Handler, resolver);
|
579 |
|
580 | function settleAt(i, x, resolver) {
|
581 |
|
582 | this[i] = x;
|
583 | if(--pending === 0) {
|
584 | resolver.become(new Fulfilled(this));
|
585 | }
|
586 | }
|
587 | }
|
588 |
|
589 | |
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 | function race(promises) {
|
604 |
|
605 |
|
606 | if(Object(promises) === promises && promises.length === 0) {
|
607 | return never();
|
608 | }
|
609 |
|
610 | var h = new Pending();
|
611 | var i, x;
|
612 | for(i=0; i<promises.length; ++i) {
|
613 | x = promises[i];
|
614 | if (x !== void 0 && i in promises) {
|
615 | getHandler(x).visit(h, h.resolve, h.reject);
|
616 | }
|
617 | }
|
618 | return new Promise(Handler, h);
|
619 | }
|
620 |
|
621 |
|
622 |
|
623 |
|
624 | |
625 |
|
626 |
|
627 |
|
628 |
|
629 | function getHandler(x) {
|
630 | if(isPromise(x)) {
|
631 | return x._handler.join();
|
632 | }
|
633 | return maybeThenable(x) ? getHandlerUntrusted(x) : new Fulfilled(x);
|
634 | }
|
635 |
|
636 | |
637 |
|
638 |
|
639 |
|
640 |
|
641 | function getHandlerUntrusted(x) {
|
642 | try {
|
643 | var untrustedThen = x.then;
|
644 | return typeof untrustedThen === 'function'
|
645 | ? new Thenable(untrustedThen, x)
|
646 | : new Fulfilled(x);
|
647 | } catch(e) {
|
648 | return new Rejected(e);
|
649 | }
|
650 | }
|
651 |
|
652 | |
653 |
|
654 |
|
655 |
|
656 | function Handler() {}
|
657 |
|
658 | Handler.prototype.when
|
659 | = Handler.prototype.become
|
660 | = Handler.prototype.notify
|
661 | = Handler.prototype.fail
|
662 | = Handler.prototype._unreport
|
663 | = Handler.prototype._report
|
664 | = noop;
|
665 |
|
666 | Handler.prototype._state = 0;
|
667 |
|
668 | Handler.prototype.state = function() {
|
669 | return this._state;
|
670 | };
|
671 |
|
672 | |
673 |
|
674 |
|
675 |
|
676 |
|
677 | Handler.prototype.join = function() {
|
678 | var h = this;
|
679 | while(h.handler !== void 0) {
|
680 | h = h.handler;
|
681 | }
|
682 | return h;
|
683 | };
|
684 |
|
685 | Handler.prototype.chain = function(to, receiver, fulfilled, rejected, progress) {
|
686 | this.when({
|
687 | resolver: to,
|
688 | receiver: receiver,
|
689 | fulfilled: fulfilled,
|
690 | rejected: rejected,
|
691 | progress: progress
|
692 | });
|
693 | };
|
694 |
|
695 | Handler.prototype.visit = function(receiver, fulfilled, rejected, progress) {
|
696 | this.chain(failIfRejected, receiver, fulfilled, rejected, progress);
|
697 | };
|
698 |
|
699 | Handler.prototype.fold = function(f, z, c, to) {
|
700 | this.visit(to, function(x) {
|
701 | f.call(c, z, x, this);
|
702 | }, to.reject, to.notify);
|
703 | };
|
704 |
|
705 | |
706 |
|
707 |
|
708 |
|
709 | function FailIfRejected() {}
|
710 |
|
711 | inherit(Handler, FailIfRejected);
|
712 |
|
713 | FailIfRejected.prototype.become = function(h) {
|
714 | h.fail();
|
715 | };
|
716 |
|
717 | var failIfRejected = new FailIfRejected();
|
718 |
|
719 | |
720 |
|
721 |
|
722 |
|
723 | function Pending(receiver, inheritedContext) {
|
724 | Promise.createContext(this, inheritedContext);
|
725 |
|
726 | this.consumers = void 0;
|
727 | this.receiver = receiver;
|
728 | this.handler = void 0;
|
729 | this.resolved = false;
|
730 | }
|
731 |
|
732 | inherit(Handler, Pending);
|
733 |
|
734 | Pending.prototype._state = 0;
|
735 |
|
736 | Pending.prototype.resolve = function(x) {
|
737 | this.become(getHandler(x));
|
738 | };
|
739 |
|
740 | Pending.prototype.reject = function(x) {
|
741 | if(this.resolved) {
|
742 | return;
|
743 | }
|
744 |
|
745 | this.become(new Rejected(x));
|
746 | };
|
747 |
|
748 | Pending.prototype.join = function() {
|
749 | if (!this.resolved) {
|
750 | return this;
|
751 | }
|
752 |
|
753 | var h = this;
|
754 |
|
755 | while (h.handler !== void 0) {
|
756 | h = h.handler;
|
757 | if (h === this) {
|
758 | return this.handler = cycle();
|
759 | }
|
760 | }
|
761 |
|
762 | return h;
|
763 | };
|
764 |
|
765 | Pending.prototype.run = function() {
|
766 | var q = this.consumers;
|
767 | var handler = this.join();
|
768 | this.consumers = void 0;
|
769 |
|
770 | for (var i = 0; i < q.length; ++i) {
|
771 | handler.when(q[i]);
|
772 | }
|
773 | };
|
774 |
|
775 | Pending.prototype.become = function(handler) {
|
776 | if(this.resolved) {
|
777 | return;
|
778 | }
|
779 |
|
780 | this.resolved = true;
|
781 | this.handler = handler;
|
782 | if(this.consumers !== void 0) {
|
783 | tasks.enqueue(this);
|
784 | }
|
785 |
|
786 | if(this.context !== void 0) {
|
787 | handler._report(this.context);
|
788 | }
|
789 | };
|
790 |
|
791 | Pending.prototype.when = function(continuation) {
|
792 | if(this.resolved) {
|
793 | tasks.enqueue(new ContinuationTask(continuation, this.handler));
|
794 | } else {
|
795 | if(this.consumers === void 0) {
|
796 | this.consumers = [continuation];
|
797 | } else {
|
798 | this.consumers.push(continuation);
|
799 | }
|
800 | }
|
801 | };
|
802 |
|
803 | Pending.prototype.notify = function(x) {
|
804 | if(!this.resolved) {
|
805 | tasks.enqueue(new ProgressTask(x, this));
|
806 | }
|
807 | };
|
808 |
|
809 | Pending.prototype.fail = function(context) {
|
810 | var c = typeof context === 'undefined' ? this.context : context;
|
811 | this.resolved && this.handler.join().fail(c);
|
812 | };
|
813 |
|
814 | Pending.prototype._report = function(context) {
|
815 | this.resolved && this.handler.join()._report(context);
|
816 | };
|
817 |
|
818 | Pending.prototype._unreport = function() {
|
819 | this.resolved && this.handler.join()._unreport();
|
820 | };
|
821 |
|
822 | |
823 |
|
824 |
|
825 |
|
826 |
|
827 | function Delegating(handler) {
|
828 | this.handler = handler;
|
829 | }
|
830 |
|
831 | inherit(Handler, Delegating);
|
832 |
|
833 | Delegating.prototype._report = function(context) {
|
834 | this.join()._report(context);
|
835 | };
|
836 |
|
837 | Delegating.prototype._unreport = function() {
|
838 | this.join()._unreport();
|
839 | };
|
840 |
|
841 | |
842 |
|
843 |
|
844 |
|
845 |
|
846 | function Async(handler) {
|
847 | Delegating.call(this, handler);
|
848 | }
|
849 |
|
850 | inherit(Delegating, Async);
|
851 |
|
852 | Async.prototype.when = function(continuation) {
|
853 | tasks.enqueue(new ContinuationTask(continuation, this));
|
854 | };
|
855 |
|
856 | |
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 | function Thenable(then, thenable) {
|
863 | Pending.call(this);
|
864 | tasks.enqueue(new AssimilateTask(then, thenable, this));
|
865 | }
|
866 |
|
867 | inherit(Pending, Thenable);
|
868 |
|
869 | |
870 |
|
871 |
|
872 |
|
873 |
|
874 | function Fulfilled(x) {
|
875 | Promise.createContext(this);
|
876 | this.value = x;
|
877 | }
|
878 |
|
879 | inherit(Handler, Fulfilled);
|
880 |
|
881 | Fulfilled.prototype._state = 1;
|
882 |
|
883 | Fulfilled.prototype.fold = function(f, z, c, to) {
|
884 | runContinuation3(f, z, this, c, to);
|
885 | };
|
886 |
|
887 | Fulfilled.prototype.when = function(cont) {
|
888 | runContinuation1(cont.fulfilled, this, cont.receiver, cont.resolver);
|
889 | };
|
890 |
|
891 | var errorId = 0;
|
892 |
|
893 | |
894 |
|
895 |
|
896 |
|
897 |
|
898 | function Rejected(x) {
|
899 | Promise.createContext(this);
|
900 |
|
901 | this.id = ++errorId;
|
902 | this.value = x;
|
903 | this.handled = false;
|
904 | this.reported = false;
|
905 |
|
906 | this._report();
|
907 | }
|
908 |
|
909 | inherit(Handler, Rejected);
|
910 |
|
911 | Rejected.prototype._state = -1;
|
912 |
|
913 | Rejected.prototype.fold = function(f, z, c, to) {
|
914 | to.become(this);
|
915 | };
|
916 |
|
917 | Rejected.prototype.when = function(cont) {
|
918 | if(typeof cont.rejected === 'function') {
|
919 | this._unreport();
|
920 | }
|
921 | runContinuation1(cont.rejected, this, cont.receiver, cont.resolver);
|
922 | };
|
923 |
|
924 | Rejected.prototype._report = function(context) {
|
925 | tasks.afterQueue(new ReportTask(this, context));
|
926 | };
|
927 |
|
928 | Rejected.prototype._unreport = function() {
|
929 | this.handled = true;
|
930 | tasks.afterQueue(new UnreportTask(this));
|
931 | };
|
932 |
|
933 | Rejected.prototype.fail = function(context) {
|
934 | Promise.onFatalRejection(this, context === void 0 ? this.context : context);
|
935 | };
|
936 |
|
937 | function ReportTask(rejection, context) {
|
938 | this.rejection = rejection;
|
939 | this.context = context;
|
940 | }
|
941 |
|
942 | ReportTask.prototype.run = function() {
|
943 | if(!this.rejection.handled) {
|
944 | this.rejection.reported = true;
|
945 | Promise.onPotentiallyUnhandledRejection(this.rejection, this.context);
|
946 | }
|
947 | };
|
948 |
|
949 | function UnreportTask(rejection) {
|
950 | this.rejection = rejection;
|
951 | }
|
952 |
|
953 | UnreportTask.prototype.run = function() {
|
954 | if(this.rejection.reported) {
|
955 | Promise.onPotentiallyUnhandledRejectionHandled(this.rejection);
|
956 | }
|
957 | };
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 | Promise.createContext
|
964 | = Promise.enterContext
|
965 | = Promise.exitContext
|
966 | = Promise.onPotentiallyUnhandledRejection
|
967 | = Promise.onPotentiallyUnhandledRejectionHandled
|
968 | = Promise.onFatalRejection
|
969 | = noop;
|
970 |
|
971 |
|
972 |
|
973 | var foreverPendingHandler = new Handler();
|
974 | var foreverPendingPromise = new Promise(Handler, foreverPendingHandler);
|
975 |
|
976 | function cycle() {
|
977 | return new Rejected(new TypeError('Promise cycle'));
|
978 | }
|
979 |
|
980 |
|
981 |
|
982 | |
983 |
|
984 |
|
985 |
|
986 | function ContinuationTask(continuation, handler) {
|
987 | this.continuation = continuation;
|
988 | this.handler = handler;
|
989 | }
|
990 |
|
991 | ContinuationTask.prototype.run = function() {
|
992 | this.handler.join().when(this.continuation);
|
993 | };
|
994 |
|
995 | |
996 |
|
997 |
|
998 |
|
999 | function ProgressTask(value, handler) {
|
1000 | this.handler = handler;
|
1001 | this.value = value;
|
1002 | }
|
1003 |
|
1004 | ProgressTask.prototype.run = function() {
|
1005 | var q = this.handler.consumers;
|
1006 | if(q === void 0) {
|
1007 | return;
|
1008 | }
|
1009 |
|
1010 | for (var c, i = 0; i < q.length; ++i) {
|
1011 | c = q[i];
|
1012 | runNotify(c.progress, this.value, this.handler, c.receiver, c.resolver);
|
1013 | }
|
1014 | };
|
1015 |
|
1016 | |
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 | function AssimilateTask(then, thenable, resolver) {
|
1024 | this._then = then;
|
1025 | this.thenable = thenable;
|
1026 | this.resolver = resolver;
|
1027 | }
|
1028 |
|
1029 | AssimilateTask.prototype.run = function() {
|
1030 | var h = this.resolver;
|
1031 | tryAssimilate(this._then, this.thenable, _resolve, _reject, _notify);
|
1032 |
|
1033 | function _resolve(x) { h.resolve(x); }
|
1034 | function _reject(x) { h.reject(x); }
|
1035 | function _notify(x) { h.notify(x); }
|
1036 | };
|
1037 |
|
1038 | function tryAssimilate(then, thenable, resolve, reject, notify) {
|
1039 | try {
|
1040 | then.call(thenable, resolve, reject, notify);
|
1041 | } catch (e) {
|
1042 | reject(e);
|
1043 | }
|
1044 | }
|
1045 |
|
1046 |
|
1047 |
|
1048 | |
1049 |
|
1050 |
|
1051 |
|
1052 | function isPromise(x) {
|
1053 | return x instanceof Promise;
|
1054 | }
|
1055 |
|
1056 | |
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 | function maybeThenable(x) {
|
1063 | return (typeof x === 'object' || typeof x === 'function') && x !== null;
|
1064 | }
|
1065 |
|
1066 | function runContinuation1(f, h, receiver, next) {
|
1067 | if(typeof f !== 'function') {
|
1068 | return next.become(h);
|
1069 | }
|
1070 |
|
1071 | Promise.enterContext(h);
|
1072 | tryCatchReject(f, h.value, receiver, next);
|
1073 | Promise.exitContext();
|
1074 | }
|
1075 |
|
1076 | function runContinuation3(f, x, h, receiver, next) {
|
1077 | if(typeof f !== 'function') {
|
1078 | return next.become(h);
|
1079 | }
|
1080 |
|
1081 | Promise.enterContext(h);
|
1082 | tryCatchReject3(f, x, h.value, receiver, next);
|
1083 | Promise.exitContext();
|
1084 | }
|
1085 |
|
1086 | function runNotify(f, x, h, receiver, next) {
|
1087 | if(typeof f !== 'function') {
|
1088 | return next.notify(x);
|
1089 | }
|
1090 |
|
1091 | Promise.enterContext(h);
|
1092 | tryCatchReturn(f, x, receiver, next);
|
1093 | Promise.exitContext();
|
1094 | }
|
1095 |
|
1096 | |
1097 |
|
1098 |
|
1099 |
|
1100 | function tryCatchReject(f, x, thisArg, next) {
|
1101 | try {
|
1102 | next.become(getHandler(f.call(thisArg, x)));
|
1103 | } catch(e) {
|
1104 | next.become(new Rejected(e));
|
1105 | }
|
1106 | }
|
1107 |
|
1108 | |
1109 |
|
1110 |
|
1111 | function tryCatchReject3(f, x, y, thisArg, next) {
|
1112 | try {
|
1113 | f.call(thisArg, x, y, next);
|
1114 | } catch(e) {
|
1115 | next.become(new Rejected(e));
|
1116 | }
|
1117 | }
|
1118 |
|
1119 | |
1120 |
|
1121 |
|
1122 | function tryCatchReturn(f, x, thisArg, next) {
|
1123 | try {
|
1124 | next.notify(f.call(thisArg, x));
|
1125 | } catch(e) {
|
1126 | next.notify(e);
|
1127 | }
|
1128 | }
|
1129 |
|
1130 | function inherit(Parent, Child) {
|
1131 | Child.prototype = objectCreate(Parent.prototype);
|
1132 | Child.prototype.constructor = Child;
|
1133 | }
|
1134 |
|
1135 | function noop() {}
|
1136 |
|
1137 | return Promise;
|
1138 | };
|
1139 | });
|
1140 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
1141 |
|
1142 | },{}],8:[function(require,module,exports){
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 | (function(define) { 'use strict';
|
1148 | define(function(require) {
|
1149 |
|
1150 | var cjsRequire, vertx, setTimer, clearTimer;
|
1151 |
|
1152 | cjsRequire = require;
|
1153 |
|
1154 | try {
|
1155 | vertx = cjsRequire('vertx');
|
1156 | setTimer = function (f, ms) { return vertx.setTimer(ms, f); };
|
1157 | clearTimer = vertx.cancelTimer;
|
1158 | } catch (e) {
|
1159 | setTimer = function(f, ms) { return setTimeout(f, ms); };
|
1160 | clearTimer = function(t) { return clearTimeout(t); };
|
1161 | }
|
1162 |
|
1163 | return {
|
1164 | set: setTimer,
|
1165 | clear: clearTimer
|
1166 | };
|
1167 |
|
1168 | });
|
1169 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
1170 |
|
1171 | },{}]},{},[1])
|
1172 | (1)
|
1173 | });
|
1174 | ; |
\ | No newline at end of file |