Skip to content

Commit 08cc186

Browse files
committed
fixed an issue with the queue when using custom commands
1 parent c3dfb16 commit 08cc186

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

lib/core/asynctree.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ class AsyncTree {
129129
if (!node.childNodes[i].started) {
130130
return node.childNodes[i];
131131
}
132+
133+
if (node.childNodes[i].childNodes.length > 0) {
134+
return AsyncTree.getNextChild(node.childNodes[i]);
135+
}
132136
}
133137

134138
return false;

lib/core/queue.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const EventEmitter = require('events');
22
const AsyncTree = require('./asynctree.js');
3+
const Utils = require('../util/utils.js');
34
const Node = require('./treenode.js');
45

56
class CommandQueue extends EventEmitter {
@@ -39,13 +40,7 @@ class CommandQueue extends EventEmitter {
3940
clearTimeout(this.scheduleTimeoutId);
4041
}
4142

42-
this.scheduleTimeoutId = setTimeout(() => {
43-
this.tree
44-
.traverse()
45-
.catch(err => {
46-
return err;
47-
});
48-
}, 0);
43+
this.scheduleTimeoutId = setTimeout(() => this.traverse(), 0);
4944
}
5045

5146
clearScheduled() {
@@ -66,21 +61,33 @@ class CommandQueue extends EventEmitter {
6661
return this;
6762
}
6863

69-
run() {
70-
if (this.tree.started) {
71-
return this;
72-
}
73-
74-
return this.tree
64+
traverse() {
65+
this.tree
7566
.traverse()
7667
.catch(err => {
7768
return err;
7869
})
7970
.then(err => {
80-
this.emit('queue:finished', err);
81-
82-
return err;
71+
this.done(err);
8372
});
73+
74+
return this;
75+
}
76+
77+
done(err) {
78+
this.emit('queue:finished', err);
79+
this.deferred.resolve(err);
80+
}
81+
82+
run() {
83+
if (this.tree.started) {
84+
return this;
85+
}
86+
87+
this.deferred = Utils.createPromise();
88+
this.traverse();
89+
90+
return this.deferred.promise;
8491
}
8592
}
8693

0 commit comments

Comments
 (0)