123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- "use strict";
- var rawAsap = require("./raw");
- var freeTasks = [];
- var pendingErrors = [];
- var requestErrorThrow = rawAsap.makeRequestCallFromTimer(throwFirstError);
- function throwFirstError() {
- if (pendingErrors.length) {
- throw pendingErrors.shift();
- }
- }
- module.exports = asap;
- function asap(task) {
- var rawTask;
- if (freeTasks.length) {
- rawTask = freeTasks.pop();
- } else {
- rawTask = new RawTask();
- }
- rawTask.task = task;
- rawAsap(rawTask);
- }
- function RawTask() {
- this.task = null;
- }
- RawTask.prototype.call = function () {
- try {
- this.task.call();
- } catch (error) {
- if (asap.onerror) {
-
-
-
- asap.onerror(error);
- } else {
-
-
-
- pendingErrors.push(error);
- requestErrorThrow();
- }
- } finally {
- this.task = null;
- freeTasks[freeTasks.length] = this;
- }
- };
|