File tree 1 file changed +19
-8
lines changed
1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,21 @@ var _ = require('./util')
2
2
3
3
/**
4
4
* 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.
6
20
*/
7
21
8
22
function Batcher ( ) {
@@ -68,8 +82,8 @@ p.push = function (job) {
68
82
69
83
p . flush = function ( ) {
70
84
this . flushing = true
71
- this . run ( this . queue )
72
- this . run ( this . userQueue )
85
+ run ( this . queue )
86
+ run ( this . userQueue )
73
87
this . reset ( )
74
88
}
75
89
@@ -79,14 +93,11 @@ p.flush = function () {
79
93
* @param {Array } queue
80
94
*/
81
95
82
- p . run = function ( queue ) {
96
+ function run ( queue ) {
83
97
// do not cache length because more jobs might be pushed
84
98
// as we run existing jobs
85
99
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 ( )
90
101
}
91
102
}
92
103
You can’t perform that action at this time.
0 commit comments