Skip to content

Commit d2e33d4

Browse files
committedDec 5, 2014
improve batcher comments
1 parent 714c1a1 commit d2e33d4

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed
 

‎src/batcher.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@ var _ = require('./util')
22

33
/**
44
* The Batcher maintains a job queue to be run
5-
* async on the next event loop.
5+
* async on the next event loop. A "job" can be any object
6+
* that implements the following interface:
7+
*
8+
* {
9+
* id: {Number} - optional
10+
* run: {Function}
11+
* user: {Boolean} - optional
12+
* }
13+
*
14+
* The `id` property is used to prevent duplication of jobs,
15+
* while jobs with `user:true` need to be processed after
16+
* all internal jobs have been processed first.
17+
*
18+
* In most cases a job will actually be a Watcher instance
19+
* which implements the above interface.
620
*/
721

822
function Batcher () {
@@ -68,8 +82,8 @@ p.push = function (job) {
6882

6983
p.flush = function () {
7084
this.flushing = true
71-
this.run(this.queue)
72-
this.run(this.userQueue)
85+
run(this.queue)
86+
run(this.userQueue)
7387
this.reset()
7488
}
7589

@@ -79,14 +93,11 @@ p.flush = function () {
7993
* @param {Array} queue
8094
*/
8195

82-
p.run = function (queue) {
96+
function run (queue) {
8397
// do not cache length because more jobs might be pushed
8498
// as we run existing jobs
8599
for (var i = 0; i < queue.length; i++) {
86-
var job = queue[i]
87-
if (!job.cancelled) {
88-
job.run()
89-
}
100+
queue[i].run()
90101
}
91102
}
92103

0 commit comments

Comments
 (0)
Please sign in to comment.