Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tasks example

  • Loading branch information...
commit a57de1d9ec33af847460ac4e1f6171227e2c4c60 1 parent 7ba58f4
@moshest moshest authored
Showing with 67 additions and 12 deletions.
  1. +7 −12 package.json
  2. +60 −0 tasks.js
View
19 package.json
@@ -1,16 +1,14 @@
{
- "name": "further",
- "description": "A lightweight library on Node.js",
+ "name": "further-examples",
+ "description": "further.js Examples",
"version": "0.1.0",
"author": {
"name": "Moshe Simantov",
"email": "ms@development.co.il"
},
- "scripts": {
- "start": "node app"
- },
"dependencies": {
- "async": "~0.1.22"
+ "further": "latest",
+ "express": "~3.0.0"
},
"devDependencies": {
},
@@ -20,14 +18,11 @@
"router",
"app",
"library",
- "tags"
+ "tags",
+ "examples"
],
"repository": {
"type": "git",
- "url": "git://github.com/DevelopmentIL/further.git"
- },
- "main": "index",
- "scripts": {
- "prepublish": "npm prune"
+ "url": "git://github.com/DevelopmentIL/further-examples.git"
}
}
View
60 tasks.js
@@ -0,0 +1,60 @@
+var further = require('further'),
+
+// Create a simple timeout task
+timerTask = function(timeout, name, result) {
+ name = name || ('timerTask' + timeout);
+
+ return function(callback) {
+ console.log('Timer task "' + name + '" started... (timeout: ' + timeout + ')');
+
+ setTimeout(function() {
+ console.log('Timer task "' + name + '" ended.');
+
+ callback.apply(this, result || [null, name]);
+ }, timeout);
+ };
+};
+
+// Serial
+console.log('Create serial task: "t1".');
+var t1 = new further.Serial();
+
+console.log('t1: Push task "t1-n1".');
+t1.push(timerTask(100, 't1-n1'));
+
+console.log('t1: Push task "t1-n2" with "secound" key.');
+t1.push('secound', timerTask(50, 't1-n2', [null, 1, 2, 3]));
+
+console.log('t1: Push tasks "t1-n3" and "t1-n4" with keys "3rd" and "4th".');
+t1.push({
+ '3rd': timerTask(200, 't1-n3'),
+ '4th': timerTask(10, 't1-n4')
+});
+
+// Parallel
+console.log('Create parallel task: "t2".');
+var t2 = new further.Parallel();
+
+console.log('t2: Push task "t2-timer-100".');
+t2.push(timerTask(100, 't2-timer-100'));
+
+console.log('t2: Push task "t2-timer-50".');
+t2.push(timerTask(50, 't2-timer-50', [null, 1, 2, 3]));
+
+console.log('t2: Create a next function with 500m timeout.');
+setTimeout(t2.next(), 500);
+
+
+console.log('t1: Run.');
+t1.run(function(err, results) {
+ console.log('t1: Finished with the arguments [err, results]:');
+ console.log([err, results]);
+});
+console.log('t1: Waiting for finish...');
+
+console.log('t2: Run.');
+t2.run(function(err, results) {
+ console.log('t2: Finished with the arguments [err, results]:');
+ console.log([err, results]);
+});
+console.log('t2: Waiting for finish...');
Please sign in to comment.
Something went wrong with that request. Please try again.