Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add concurrency example

  • Loading branch information...
commit cc0af336590435abd2eba06499a06da1302c9c0f 1 parent 610c380
@tj tj authored
Showing with 50 additions and 0 deletions.
  1. +25 −0 examples/concurrency.js
  2. +25 −0 examples/serial.js
View
25 examples/concurrency.js
@@ -0,0 +1,25 @@
+
+/**
+ * Module dependencies.
+ */
+
+var Batch = require('..');
+
+var n = 10;
+var batch = new Batch;
+
+batch.concurrency(3);
+
+while (n--) {
+ (function(n){
+ batch.push(function(done){
+ console.log(' start : %s', n);
+ setTimeout(function(){
+ console.log(' done : %s', n);
+ done();
+ }, 200);
+ })
+ })(n);
+}
+
+batch.end();
View
25 examples/serial.js
@@ -0,0 +1,25 @@
+
+/**
+ * Module dependencies.
+ */
+
+var Batch = require('..');
+
+var n = 10;
+var batch = new Batch;
+
+batch.concurrency(1);
+
+while (n--) {
+ (function(n){
+ batch.push(function(done){
+ console.log(' start : %s', n);
+ setTimeout(function(){
+ console.log(' done : %s', n);
+ done();
+ }, 200);
+ })
+ })(n);
+}
+
+batch.end();
Please sign in to comment.
Something went wrong with that request. Please try again.