Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

replace mplex by async, fix factory, update version

  • Loading branch information...
commit 26be4c7c9ac4829ca22b98a94e648312d5bb9d21 1 parent 55ec209
@n1t0 n1t0 authored
View
8 lib/factory.js
@@ -50,10 +50,12 @@ var factory = function(spec, my) {
var _factory; // Singleton
-exports.get = factory;
+exports.factory = factory;
-exports.expose = function(factory) {
+exports.factory_expose = function(exports, factory) {
if(!_factory)
_factory = factory({});
- return _factory;
+ exports.get = function() {
+ return _factory;
+ }
};
View
6 lib/fwk.js
@@ -30,6 +30,7 @@ var lock = require("./lock.js");
var mplex = require("./mplex.js");
var cfg = require("./cfg.js");
var factory = require("./factory.js");
+var async = require('async');
exports.method = base.method;
exports.getter = base.getter;
@@ -46,7 +47,7 @@ exports.cache = cache.cache;
exports.lock = lock.lock;
-exports.mplex = mplex.mplex;
+exports.async = async;
exports.populateConfig = cfg.populateConfig;
exports.baseConfig = cfg.baseConfig;
@@ -54,4 +55,5 @@ exports.baseConfig = cfg.baseConfig;
exports.b64encode = b64.b64encode;
exports.b64decode = b64.b64decode;
-exports.factory = factory;
+exports.factory = factory.factory;
+exports.factory_expose = factory.factory_expose;
View
112 lib/mplex.js
@@ -1,112 +0,0 @@
-// Copyright Stanislas Polu
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-var util = require('util');
-var base = require("./base.js");
-
-/**
- * mplex.js
- *
- * The mplex object allows to wait for k asynchronous operations before executing
- * a completion callback with a lightweight syntax
- *
- * Example:
- * ===================================================
- * var mplex = fwk.mplex({});
- *
- * for(...) {
- * (function(htag, cb) {
- * my.pipe.send(fwk.message({})
- * .setType('2w')
- * .setSubject('IOIDXD:SEARCH')
- * .addTarget(htag)
- * .setBody(q.json()),
- * function(err, hdr, res) {
- * ...
- * cb();
- * });
- * }(htag, mplex.callback()));
- * }
- *
- * mplex.go(function() {
- * pump(now, pos + mod, mod * 2);
- * });
- * ====================================================
- */
-
-/**
- * A MPlex is an object that allows to trigger n callback functions and
- * get one callback only when all these functions have returned
- *
- * @extends {}
- *
- * @param spec {}
- */
-var mplex = function(spec, my) {
- my = my || {};
- var _super = {};
-
- var that = {};
-
- my.cb = function() {};
-
- my.done = 0; // number of callbacks done
- my.wait = 0; // number of callbacks waiting
- my.go = false; // started?
- my.cbargs = [];
-
- // public
- var callback; /* callback() returns a callback to wait on */
- var go; /* go(cb) start waiting for generated callbacks */
-
- /* callback()
- * returns a callback to wait on */
- callback = function() {
- my.wait ++;
- return function() {
- my.cbargs.push(arguments);
- my.wait --;
- my.done ++;
- if(my.wait === 0 && my.go)
- my.cb(my.cbargs);
- };
- };
-
- /* go(cb)
- * start waiting for generated callbacks */
- go = function(cb) {
- if(cb === null || typeof cb === "undefined")
- throw new TypeError();
- my.cb = cb;
- my.go = true;
- if(my.wait === 0) {
- my.cb(my.cbargs);
- }
- };
-
- base.method(that, 'callback', callback);
- base.method(that, 'go', go);
- base.getter(that, 'cbargs', my, 'cbargs');
-
- return that;
-};
-
-exports.mplex = mplex;
View
5 package.json
@@ -1,6 +1,6 @@
{
"name": "fwk",
- "version": "0.1.19",
+ "version": "1.0.1",
"description": "Simple JS framework for node.js",
"keywords": ["fwk", "node"],
"homepage": "https://github.com/teleportd/fwk",
@@ -10,7 +10,8 @@
"repository" : { "type" : "git",
"url" : "http://github.com/teleportd/fwk.git" },
"dependencies": {
- "should": "0.6.x"
+ "should": "0.6.x",
+ "async": "0.1.x"
},
"main" : "./lib/fwk",
"engines" : { "node" : ">=0.4.0" }
View
26 test/unit.mplex.js
@@ -1,26 +0,0 @@
-var util = require('util');
-/**
- * Test dependencies.
- */
-
-var mplex = require("../lib/mplex.js").mplex();
-var should = require('should');
-
-describe("unit:mplex", function() {
-
- it('callback and go', function(){
- var j = 0;
- for(var i = 0; i < 4; i++) {
- (function(cb) {
- setTimeout(function() {
- j++;
- cb();
- }, 1);
- })(mplex.callback());
- }
- mplex.go(function() {
- j.should.equal(4);
- });
- });
-
-});
Please sign in to comment.
Something went wrong with that request. Please try again.