1 // https://d3js.org/d3-queue/ Version 3.0.5. Copyright 2017 Mike Bostock.
2 (function (global
, factory
) {
3 typeof exports
=== 'object' && typeof module
!== 'undefined' ? factory(exports
) :
4 typeof define
=== 'function' && define
.amd
? define(['exports'], factory
) :
5 (factory((global
.d3
= global
.d3
|| {})));
6 }(this, (function (exports
) { 'use strict';
12 function Queue(size
) {
13 if (!(size
>= 1)) throw new Error
;
22 this._start
= 0; // inside a synchronous task callback?
25 Queue
.prototype = queue
.prototype = {
27 defer: function(callback
) {
28 if (typeof callback
!== "function" || this._call
) throw new Error
;
29 if (this._error
!= null) return this;
30 var t
= slice
.call(arguments
, 1);
32 ++this._waiting
, this._tasks
.push(t
);
37 if (this._error
== null) abort(this, new Error("abort"));
40 await: function(callback
) {
41 if (typeof callback
!== "function" || this._call
) throw new Error
;
42 this._call = function(error
, results
) { callback
.apply(null, [error
].concat(results
)); };
46 awaitAll: function(callback
) {
47 if (typeof callback
!== "function" || this._call
) throw new Error
;
48 this._call
= callback
;
56 try { start(q
); } // let the current task complete
58 if (q
._tasks
[q
._ended
+ q
._active
- 1]) abort(q
, e
); // task errored synchronously
59 else if (!q
._data
) throw e
; // await callback errored synchronously
65 while (q
._start
= q
._waiting
&& q
._active
< q
._size
) {
66 var i
= q
._ended
+ q
._active
,
71 --q
._waiting
, ++q
._active
;
73 if (!q
._tasks
[i
]) continue; // task finished synchronously
74 q
._tasks
[i
] = t
|| noabort
;
79 return function(e
, r
) {
80 if (!q
._tasks
[i
]) return; // ignore multiple callbacks
81 --q
._active
, ++q
._ended
;
83 if (q
._error
!= null) return; // ignore secondary errors
88 if (q
._waiting
) poke(q
);
94 function abort(q
, e
) {
95 var i
= q
._tasks
.length
, t
;
96 q
._error
= e
; // ignore active callbacks
97 q
._data
= undefined; // allow gc
98 q
._waiting
= NaN
; // prevent starting
101 if (t
= q
._tasks
[i
]) {
105 catch (e
) { /* ignore */ }
110 q
._active
= NaN
; // allow notification
114 function maybeNotify(q
) {
115 if (!q
._active
&& q
._call
) {
117 q
._data
= undefined; // allow gc
118 q
._call(q
._error
, d
);
122 function queue(concurrency
) {
123 return new Queue(arguments
.length
? +concurrency
: Infinity
);
126 exports
.queue
= queue
;
128 Object
.defineProperty(exports
, '__esModule', { value
: true });