From ccf685f3f28722579210215064dcb9b28d8033e9 Mon Sep 17 00:00:00 2001 From: David Wee Date: Mon, 28 Apr 2014 23:51:25 -0700 Subject: [PATCH] set method --- README.md | 21 ++++++++++++++++++++- index.js | 6 ++++++ package.json | 2 +- test/test-set.js | 22 ++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/test-set.js diff --git a/README.md b/README.md index b69d828..61f55fd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ New! ==== -Key value store across series! +Key value store across series! Just call .done(hash) to store the keys/values of the hash queue.series([ function(lib) { @@ -17,6 +17,25 @@ Key value store across series! } ]); + +You can also use .set(hash) + + queue.series([ + function(lib) { + lib.set({one:1}); + lib.done() + }, + function(lib) { + lib.set({life:42}) + lib.done() + }, + function(lib) { + t.equal(43,lib.get('one') + lib.get('life')); + lib.done(); + } + ]); + + New! ==== Early termination flow control in .series! diff --git a/index.js b/index.js index 4204547..41c5a9e 100644 --- a/index.js +++ b/index.js @@ -90,6 +90,12 @@ function qlib(myWorkFunction) { this.hash = {}; this.get = function(key) { return this.hash[key]; + } + this.set = function(obj) { + if ((obj) && (typeof obj == 'object')) { + Hash(this.hash).update(obj); + } + return true; } this.done = function(obj) { if ((obj) && (typeof obj == 'object')) { diff --git a/package.json b/package.json index ac63a0b..819052a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "David Wee (http://rook2pawn.com)", "name": "queuelib", "description": "Straightforward asynchronous queue processor", - "version": "0.3.5", + "version": "0.3.6", "homepage": "https://github.com/rook2pawn/node-queuelib", "repository": { "type": "git", diff --git a/test/test-set.js b/test/test-set.js new file mode 100644 index 0000000..114ea13 --- /dev/null +++ b/test/test-set.js @@ -0,0 +1,22 @@ + +var test = require('tape'); + +test('testSet',function(t) { + t.plan(1); + var Q = require('../'); + var queue = new Q; + queue.series([ + function(lib) { + lib.set({one:1}); + lib.done() + }, + function(lib) { + lib.set({life:42}) + lib.done() + }, + function(lib) { + t.equal(43,lib.get('one') + lib.get('life')); + lib.done(); + } + ]); +});