collect-your-stuff 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +32 -3926
  2. package/browser/collect-your-stuff.js +912 -549
  3. package/browser/collect-your-stuff.min.js +1 -1
  4. package/dist/collections/arrayable/ArrayElement.d.ts +6 -11
  5. package/dist/collections/arrayable/ArrayElement.js +5 -7
  6. package/dist/collections/arrayable/Arrayable.d.ts +22 -37
  7. package/dist/collections/arrayable/Arrayable.js +208 -223
  8. package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +9 -14
  9. package/dist/collections/doubly-linked-list/DoubleLinker.js +71 -73
  10. package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +19 -36
  11. package/dist/collections/doubly-linked-list/DoublyLinkedList.js +310 -327
  12. package/dist/collections/linked-list/LinkedList.d.ts +20 -36
  13. package/dist/collections/linked-list/LinkedList.js +283 -296
  14. package/dist/collections/linked-list/Linker.d.ts +8 -13
  15. package/dist/collections/linked-list/Linker.js +82 -84
  16. package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +24 -43
  17. package/dist/collections/linked-tree-list/LinkedTreeList.js +274 -294
  18. package/dist/collections/linked-tree-list/TreeLinker.d.ts +14 -20
  19. package/dist/collections/linked-tree-list/TreeLinker.js +91 -94
  20. package/dist/collections/queue/Queue.d.ts +10 -14
  21. package/dist/collections/queue/Queue.js +114 -121
  22. package/dist/collections/queue/Queueable.d.ts +13 -22
  23. package/dist/collections/queue/Queueable.js +142 -148
  24. package/dist/collections/queue/TaskQueue.d.ts +8 -17
  25. package/dist/collections/queue/TaskQueue.js +128 -137
  26. package/dist/collections/scoped-collection/ScopedCollection.d.ts +42 -0
  27. package/dist/collections/scoped-collection/ScopedCollection.js +81 -0
  28. package/dist/collections/scoped-collection/ScopedCollection.min.js +1 -0
  29. package/dist/collections/stack/Stack.d.ts +11 -15
  30. package/dist/collections/stack/Stack.js +122 -129
  31. package/dist/collections/stack/Stackable.d.ts +9 -16
  32. package/dist/collections/stack/Stackable.js +81 -85
  33. package/dist/collections/stack/TaskStack.d.ts +8 -17
  34. package/dist/collections/stack/TaskStack.js +98 -107
  35. package/dist/main.d.ts +67 -68
  36. package/dist/main.js +8 -4
  37. package/dist/main.min.js +1 -1
  38. package/dist/recipes/ArrayIterator.d.ts +4 -4
  39. package/dist/recipes/ArrayIterator.js +4 -4
  40. package/dist/recipes/DoubleLinkerIterator.d.ts +3 -3
  41. package/dist/recipes/DoubleLinkerIterator.js +3 -3
  42. package/dist/recipes/IsArrayable.d.ts +13 -33
  43. package/dist/recipes/IsQueue.d.ts +4 -9
  44. package/dist/recipes/IsScopedCollection.d.ts +27 -0
  45. package/dist/recipes/IsScopedCollection.js +5 -0
  46. package/dist/recipes/IsScopedCollection.min.js +1 -0
  47. package/dist/recipes/IsStack.d.ts +4 -9
  48. package/dist/recipes/IsTreeNode.d.ts +1 -1
  49. package/dist/recipes/LinkerIterator.d.ts +3 -3
  50. package/dist/recipes/LinkerIterator.js +3 -3
  51. package/dist/recipes/Runnable.d.ts +3 -16
  52. package/dist/recipes/Runnable.js +3 -9
  53. package/dist/recipes/TreeLinkerIterator.d.ts +4 -4
  54. package/dist/recipes/TreeLinkerIterator.js +36 -36
  55. package/dist/recipes/recipes.d.ts +1 -4
  56. package/dist/recipes/recipes.js +19 -22
  57. package/dist/services/parseTree.d.ts +2 -3
  58. package/dist/services/parseTree.js +23 -24
  59. package/dist/services/parseTreeNext.d.ts +2 -3
  60. package/dist/services/parseTreeNext.js +2 -3
  61. package/dist/services/services.d.ts +1 -4
  62. package/dist/services/services.js +19 -22
  63. package/package.json +4 -4
@@ -1,148 +1,142 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.Queueable = void 0
7
- const _Linker = require('../linked-list/Linker')
8
- /**
9
- * Queueable represents a runnable entry in a queue.
10
- * @extends Linker
11
- */
12
- class Queueable {
13
- /**
14
- * Create a queueable item that can be used in a queue.
15
- * @param {Object} [queueableData={}] The settings for the new queueable.
16
- * @param {*} [queueableData.task=null] The data to be stored in this queueable
17
- * @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
18
- * @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
19
- */
20
- constructor ({
21
- task = null,
22
- next = null,
23
- ready = false
24
- } = {}) {
25
- /** The task (or data) this queueable holds. */
26
- this.data = null
27
- /** The queueable after this one, or null when this is the last. */
28
- this.next = null
29
- /** Whether this queueable has been run to completion. */
30
- this.complete = false
31
- /** Whether this queueable may run, or a function which answers that when asked. */
32
- this.ready = false
33
- /** Whether this queueable is running right now. */
34
- this.running = false
35
- this.classType = Queueable
36
- this.data = task
37
- this.next = next
38
- this.complete = false
39
- this.ready = ready
40
- this.running = false
41
- }
42
-
43
- /**
44
- * Check ready state.
45
- * @return {boolean}
46
- */
47
- get isReady () {
48
- return typeof this.ready === 'function' ? this.ready() : this.ready
49
- }
50
-
51
- /**
52
- * Retrieve the data which should be formed as a task.
53
- * @return {*}
54
- */
55
- get task () {
56
- if (typeof this.data === 'function') {
57
- return this.data
58
- }
59
- return complete => typeof complete === 'function'
60
- ? complete({
61
- context: this.data
62
- }).context
63
- : this.data
64
- }
65
-
66
- /**
67
- * Set this queueable as completed.
68
- * @param {Object} [completeResponse={}] The result to report for the task.
69
- * @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
70
- * @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
71
- * @param {*} [completeResponse.context=null] Provide additional data in the response
72
- * @return {completeResponse}
73
- */
74
- markCompleted ({
75
- success = true,
76
- error = false,
77
- context = null
78
- } = {}) {
79
- this.complete = true
80
- this.running = false
81
- return {
82
- success,
83
- error,
84
- context
85
- }
86
- }
87
-
88
- /**
89
- * Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
90
- * @return {completeResponse}
91
- */
92
- run () {
93
- if (!this.isReady) {
94
- // Not yet ready, return with errors
95
- return {
96
- success: false,
97
- error: 'Task is not ready',
98
- context: this.data
99
- }
100
- }
101
- if (this.running) {
102
- // Already running, return error since we cannot run again
103
- return {
104
- success: false,
105
- error: 'Queued task is already running, possible missing \'complete\' callback',
106
- context: this.data
107
- }
108
- }
109
- this.running = true
110
- // Wrap the task in the markCompleted function, so we can set flags and format the response
111
- return this.task(this.markCompleted.bind(this))
112
- }
113
- }
114
- /**
115
- * Make a new Queueable from the data given if it is not already a valid Queueable.
116
- * @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
117
- * @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
118
- * @return {Queueable}
119
- */
120
- exports.Queueable = Queueable
121
- Queueable.make = (queueable, classType = Queueable) => {
122
- if (queueable === null || typeof queueable !== 'object') {
123
- // It is not an object (or it is null), so instantiate the Queueable with an element as the data
124
- return new classType({
125
- task: queueable,
126
- ready: true
127
- })
128
- }
129
- if (queueable.classType) {
130
- // Already valid Queueable, return as-is
131
- return queueable
132
- }
133
- if (!('task' in queueable)) {
134
- queueable = {
135
- task: queueable,
136
- ready: true
137
- }
138
- }
139
- // Create the new node as the configured #classType
140
- return new classType(queueable)
141
- }
142
- /**
143
- * Convert an array into Queueable instances, return the head and tail Queueables.
144
- * @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
145
- * @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
146
- * @returns {{head: Queueable, tail: Queueable}}
147
- */
148
- Queueable.fromArray = (values = [], classType = Queueable) => _Linker.Linker.fromArray(values, classType)
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.Queueable = void 0
7
+ const _Linker = require('../linked-list/Linker')
8
+ /**
9
+ * Queueable represents a runnable entry in a queue.
10
+ * @extends Linker
11
+ */
12
+ class Queueable {
13
+ /**
14
+ * Create a queueable item that can be used in a queue.
15
+ * @param queueableData The settings for the new queueable.
16
+ * @param queueableData.task The data to be stored in this queueable
17
+ * @param queueableData.next The reference to the next queueable if any
18
+ * @param queueableData.ready Indicate if the queueable is ready to run
19
+ */
20
+ constructor ({
21
+ task = null,
22
+ next = null,
23
+ ready = false
24
+ } = {}) {
25
+ /** The task (or data) this queueable holds. */
26
+ this.data = null
27
+ /** The queueable after this one, or null when this is the last. */
28
+ this.next = null
29
+ /** Whether this queueable has been run to completion. */
30
+ this.complete = false
31
+ /** Whether this queueable may run, or a function which answers that when asked. */
32
+ this.ready = false
33
+ /** Whether this queueable is running right now. */
34
+ this.running = false
35
+ this.classType = Queueable
36
+ this.data = task
37
+ this.next = next
38
+ this.complete = false
39
+ this.ready = ready
40
+ this.running = false
41
+ }
42
+
43
+ /**
44
+ * Check ready state.
45
+ */
46
+ get isReady () {
47
+ return typeof this.ready === 'function' ? this.ready() : this.ready
48
+ }
49
+
50
+ /**
51
+ * Retrieve the data which should be formed as a task.
52
+ */
53
+ get task () {
54
+ if (typeof this.data === 'function') {
55
+ return this.data
56
+ }
57
+ return complete => typeof complete === 'function'
58
+ ? complete({
59
+ context: this.data
60
+ }).context
61
+ : this.data
62
+ }
63
+
64
+ /**
65
+ * Set this queueable as completed.
66
+ * @param completeResponse The result to report for the task.
67
+ * @param completeResponse.success Indicate when the task failed (use false) or give a success message
68
+ * @param completeResponse.error Indicate a task was error-free (use false) or give an error message
69
+ * @param completeResponse.context Provide additional data in the response
70
+ */
71
+ markCompleted ({
72
+ success = true,
73
+ error = false,
74
+ context = null
75
+ } = {}) {
76
+ this.complete = true
77
+ this.running = false
78
+ return {
79
+ success,
80
+ error,
81
+ context
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
87
+ */
88
+ run () {
89
+ if (!this.isReady) {
90
+ // Not yet ready, return with errors
91
+ return {
92
+ success: false,
93
+ error: 'Task is not ready',
94
+ context: this.data
95
+ }
96
+ }
97
+ if (this.running) {
98
+ // Already running, return error since we cannot run again
99
+ return {
100
+ success: false,
101
+ error: 'Queued task is already running, possible missing \'complete\' callback',
102
+ context: this.data
103
+ }
104
+ }
105
+ this.running = true
106
+ // Wrap the task in the markCompleted function, so we can set flags and format the response
107
+ return this.task(this.markCompleted.bind(this))
108
+ }
109
+ }
110
+ /**
111
+ * Make a new Queueable from the data given if it is not already a valid Queueable.
112
+ * @param queueable Return a valid Queueable instance from given data, or even an already valid one.
113
+ * @param classType Provide the type of IsLinker to use.
114
+ */
115
+ exports.Queueable = Queueable
116
+ Queueable.make = (queueable, classType = Queueable) => {
117
+ if (queueable === null || typeof queueable !== 'object') {
118
+ // It is not an object (or it is null), so instantiate the Queueable with an element as the data
119
+ return new classType({
120
+ task: queueable,
121
+ ready: true
122
+ })
123
+ }
124
+ if (queueable.classType) {
125
+ // Already valid Queueable, return as-is
126
+ return queueable
127
+ }
128
+ if (!('task' in queueable)) {
129
+ queueable = {
130
+ task: queueable,
131
+ ready: true
132
+ }
133
+ }
134
+ // Create the new node as the configured #classType
135
+ return new classType(queueable)
136
+ }
137
+ /**
138
+ * Convert an array into Queueable instances, return the head and tail Queueables.
139
+ * @param values Provide an array of data that will be converted to a chain of queueable linkers.
140
+ * @param classType Provide the type of IsLinker to use.
141
+ */
142
+ Queueable.fromArray = (values = [], classType = Queueable) => _Linker.Linker.fromArray(values, classType)
@@ -1,8 +1,5 @@
1
1
  /**
2
- * @file task queue
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.1.0
5
- * @memberOf module:collect-your-stuff
2
+ * task queue
6
3
  */
7
4
  import { Queueable } from './Queueable';
8
5
  import { IsArrayable } from '../../recipes/IsArrayable';
@@ -20,49 +17,43 @@ export declare class TaskQueue {
20
17
  private queueableClass;
21
18
  /**
22
19
  * Instantiate the queue with the given queue list.
23
- * @param {Iterable|LinkedList} queuedList Give the list of queueables to start in this queue.
24
- * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no queued list is given.
25
- * @param {Queueable} [queueableClass=Queueable] The class used to wrap queued items.
20
+ * @param queuedList Give the list of queueables to start in this queue.
21
+ * @param listClass The type of list to create when no queued list is given.
22
+ * @param queueableClass The class used to wrap queued items.
26
23
  */
27
24
  constructor(queuedList?: IsArrayable<any>, listClass?: any, queueableClass?: typeof Queueable);
28
25
  /**
29
26
  * Take a queued task from the front of the queue and run it if ready. A task which is not ready yet is kept in the
30
27
  * queue (never dropped), a task which is still running is reported as blocking and left to finish on its own, and
31
28
  * completed tasks are discarded.
32
- * @return {completeResponse|*}
33
29
  */
34
30
  dequeue(): completeResponse | any;
35
31
  /**
36
32
  * Return true if the queue is empty (there are no tasks in the queue list)
37
- * @return {boolean}
38
33
  */
39
34
  empty(): boolean;
40
35
  /**
41
36
  * Add a queued task to the end of the queue
42
- * @param {Queueable} queueable Add a new queueable to the end of the queue
37
+ * @param queueable Add a new queueable to the end of the queue
43
38
  */
44
39
  enqueue(queueable: Queueable): void;
45
40
  /**
46
41
  * Take a look at the next queued task
47
- * @return {Queueable}
48
42
  */
49
43
  peek(): IsLinker;
50
44
  /**
51
45
  * Remove the next queued item and return it.
52
- * @return {Queueable|null}
53
46
  */
54
47
  remove(): Queueable | null;
55
48
  /**
56
49
  * Get the length of the current queue.
57
- * @return {number}
58
50
  */
59
51
  size(): number;
60
52
  /**
61
53
  * Convert an array to a TaskQueue.
62
- * @param {Array} values An array of values which will be converted to queueables in this queue
63
- * @param {Queueable} queueableClass The class to use for each queueable
64
- * @param {TaskQueue|Iterable} listClass The class to use to manage the queueables
65
- * @returns {TaskQueue}
54
+ * @param values An array of values which will be converted to queueables in this queue
55
+ * @param queueableClass The class to use for each queueable
56
+ * @param listClass The class to use to manage the queueables
66
57
  */
67
58
  static fromArray: (values?: Array<any>, queueableClass?: typeof Queueable, listClass?: any) => TaskQueue;
68
59
  }
@@ -1,137 +1,128 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.TaskQueue = void 0
7
- const _Queueable = require('./Queueable')
8
- const _LinkedList = require('../linked-list/LinkedList')
9
- /**
10
- * @file task queue
11
- * @author Joshua Heagle <joshuaheagle@gmail.com>
12
- * @version 1.1.0
13
- * @memberOf module:collect-your-stuff
14
- */
15
-
16
- /**
17
- * Maintain a series of queued tasks (Queueables): dequeue() takes the next task from the front and RUNS it, giving each
18
- * task in turn a chance to run (a task which is not ready, or which has not finished, is placed at the back again).
19
- * This is a task scheduler, for a plain first-in-first-out collection of items use Queue.
20
- */
21
- class TaskQueue {
22
- /**
23
- * Instantiate the queue with the given queue list.
24
- * @param {Iterable|LinkedList} queuedList Give the list of queueables to start in this queue.
25
- * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no queued list is given.
26
- * @param {Queueable} [queueableClass=Queueable] The class used to wrap queued items.
27
- */
28
- constructor (queuedList = null, listClass = _LinkedList.LinkedList, queueableClass = _Queueable.Queueable) {
29
- this.listClass = listClass
30
- this.queueableClass = queueableClass
31
- if (queuedList === null) {
32
- queuedList = new listClass(queueableClass)
33
- }
34
- this.queuedList = queuedList
35
- }
36
-
37
- /**
38
- * Take a queued task from the front of the queue and run it if ready. A task which is not ready yet is kept in the
39
- * queue (never dropped), a task which is still running is reported as blocking and left to finish on its own, and
40
- * completed tasks are discarded.
41
- * @return {completeResponse|*}
42
- */
43
- dequeue () {
44
- let next = this.remove()
45
- // Tasks which already completed are discarded when they reach the front of the queue
46
- while (next && next.complete) {
47
- next = this.remove()
48
- }
49
- if (!next) {
50
- return {
51
- success: 'No more queueable tasks in the queue',
52
- error: false,
53
- context: this.queuedList
54
- }
55
- }
56
- if (next.running) {
57
- // The unfinished task reports back through its own complete callback, so it is not kept in the queue
58
- return {
59
- success: false,
60
- error: 'The queue has been blocked by an unfinished task.',
61
- context: next
62
- }
63
- }
64
- if (!next.isReady) {
65
- // Keep the task (at the back, so the next dequeue can try the other tasks) rather than losing it
66
- this.enqueue(next)
67
- // We could go check the next in queue here but if we end up in a state where nothing is ready it would infinite loop
68
- // Also, we want the loop handled externally
69
- return {
70
- success: false,
71
- error: 'Unable to find ready task.',
72
- context: next
73
- }
74
- }
75
- if (!this.empty()) {
76
- // Place back in queue to be checked once again next time, only if the queue will not be empty
77
- this.enqueue(next)
78
- }
79
- return next.run.call(next)
80
- }
81
-
82
- /**
83
- * Return true if the queue is empty (there are no tasks in the queue list)
84
- * @return {boolean}
85
- */
86
- empty () {
87
- return this.size() <= 0
88
- }
89
-
90
- /**
91
- * Add a queued task to the end of the queue
92
- * @param {Queueable} queueable Add a new queueable to the end of the queue
93
- */
94
- enqueue (queueable) {
95
- this.queuedList.append(queueable)
96
- }
97
-
98
- /**
99
- * Take a look at the next queued task
100
- * @return {Queueable}
101
- */
102
- peek () {
103
- return this.queuedList.first
104
- }
105
-
106
- /**
107
- * Remove the next queued item and return it.
108
- * @return {Queueable|null}
109
- */
110
- remove () {
111
- if (this.empty()) {
112
- return null
113
- }
114
- return this.queuedList.remove(this.queuedList.first)
115
- }
116
-
117
- /**
118
- * Get the length of the current queue.
119
- * @return {number}
120
- */
121
- size () {
122
- return this.queuedList.length
123
- }
124
- }
125
- /**
126
- * Convert an array to a TaskQueue.
127
- * @param {Array} values An array of values which will be converted to queueables in this queue
128
- * @param {Queueable} queueableClass The class to use for each queueable
129
- * @param {TaskQueue|Iterable} listClass The class to use to manage the queueables
130
- * @returns {TaskQueue}
131
- */
132
- exports.TaskQueue = TaskQueue
133
- TaskQueue.fromArray = (values = [], queueableClass = _Queueable.Queueable, listClass = _LinkedList.LinkedList) => {
134
- const list = new listClass(queueableClass)
135
- list.initialize(queueableClass.fromArray(values, queueableClass).head)
136
- return new TaskQueue(list, listClass, queueableClass)
137
- }
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.TaskQueue = void 0
7
+ const _Queueable = require('./Queueable')
8
+ const _LinkedList = require('../linked-list/LinkedList')
9
+ /**
10
+ * task queue
11
+ */
12
+
13
+ /**
14
+ * Maintain a series of queued tasks (Queueables): dequeue() takes the next task from the front and RUNS it, giving each
15
+ * task in turn a chance to run (a task which is not ready, or which has not finished, is placed at the back again).
16
+ * This is a task scheduler, for a plain first-in-first-out collection of items use Queue.
17
+ */
18
+ class TaskQueue {
19
+ /**
20
+ * Instantiate the queue with the given queue list.
21
+ * @param queuedList Give the list of queueables to start in this queue.
22
+ * @param listClass The type of list to create when no queued list is given.
23
+ * @param queueableClass The class used to wrap queued items.
24
+ */
25
+ constructor (queuedList = null, listClass = _LinkedList.LinkedList, queueableClass = _Queueable.Queueable) {
26
+ this.listClass = listClass
27
+ this.queueableClass = queueableClass
28
+ if (queuedList === null) {
29
+ queuedList = new listClass(queueableClass)
30
+ }
31
+ this.queuedList = queuedList
32
+ }
33
+
34
+ /**
35
+ * Take a queued task from the front of the queue and run it if ready. A task which is not ready yet is kept in the
36
+ * queue (never dropped), a task which is still running is reported as blocking and left to finish on its own, and
37
+ * completed tasks are discarded.
38
+ */
39
+ dequeue () {
40
+ let next = this.remove()
41
+ // Tasks which already completed are discarded when they reach the front of the queue
42
+ while (next && next.complete) {
43
+ next = this.remove()
44
+ }
45
+ if (!next) {
46
+ return {
47
+ success: 'No more queueable tasks in the queue',
48
+ error: false,
49
+ context: this.queuedList
50
+ }
51
+ }
52
+ if (next.running) {
53
+ // The unfinished task reports back through its own complete callback, so it is not kept in the queue
54
+ return {
55
+ success: false,
56
+ error: 'The queue has been blocked by an unfinished task.',
57
+ context: next
58
+ }
59
+ }
60
+ if (!next.isReady) {
61
+ // Keep the task (at the back, so the next dequeue can try the other tasks) rather than losing it
62
+ this.enqueue(next)
63
+ // We could go check the next in queue here but if we end up in a state where nothing is ready it would infinite loop
64
+ // Also, we want the loop handled externally
65
+ return {
66
+ success: false,
67
+ error: 'Unable to find ready task.',
68
+ context: next
69
+ }
70
+ }
71
+ if (!this.empty()) {
72
+ // Place back in queue to be checked once again next time, only if the queue will not be empty
73
+ this.enqueue(next)
74
+ }
75
+ return next.run.call(next)
76
+ }
77
+
78
+ /**
79
+ * Return true if the queue is empty (there are no tasks in the queue list)
80
+ */
81
+ empty () {
82
+ return this.size() <= 0
83
+ }
84
+
85
+ /**
86
+ * Add a queued task to the end of the queue
87
+ * @param queueable Add a new queueable to the end of the queue
88
+ */
89
+ enqueue (queueable) {
90
+ this.queuedList.append(queueable)
91
+ }
92
+
93
+ /**
94
+ * Take a look at the next queued task
95
+ */
96
+ peek () {
97
+ return this.queuedList.first
98
+ }
99
+
100
+ /**
101
+ * Remove the next queued item and return it.
102
+ */
103
+ remove () {
104
+ if (this.empty()) {
105
+ return null
106
+ }
107
+ return this.queuedList.remove(this.queuedList.first)
108
+ }
109
+
110
+ /**
111
+ * Get the length of the current queue.
112
+ */
113
+ size () {
114
+ return this.queuedList.length
115
+ }
116
+ }
117
+ /**
118
+ * Convert an array to a TaskQueue.
119
+ * @param values An array of values which will be converted to queueables in this queue
120
+ * @param queueableClass The class to use for each queueable
121
+ * @param listClass The class to use to manage the queueables
122
+ */
123
+ exports.TaskQueue = TaskQueue
124
+ TaskQueue.fromArray = (values = [], queueableClass = _Queueable.Queueable, listClass = _LinkedList.LinkedList) => {
125
+ const list = new listClass(queueableClass)
126
+ list.initialize(queueableClass.fromArray(values, queueableClass).head)
127
+ return new TaskQueue(list, listClass, queueableClass)
128
+ }