Comparing version 0.0.3 to 0.0.4
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Blocking, X, | ||
var Blocking, KEY, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
X = {}; | ||
KEY = '___BLOCKING_ERROR___'; | ||
@@ -13,3 +13,3 @@ module.exports = Blocking = (function(_super) { | ||
function Blocking() { | ||
this.__x = X; | ||
this[KEY] = true; | ||
} | ||
@@ -22,3 +22,3 @@ | ||
Blocking.instance = function(i) { | ||
return (i != null ? i.__x : void 0) === X; | ||
return i instanceof Error && i[KEY] === true; | ||
}; | ||
@@ -25,0 +25,0 @@ |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Blocking, block, blocked, mabs, notifying, unblock, util, x; | ||
var Blocking, block, blocked, get, isolate, mab, mabs, reactivity, subscribe, unblock, util, x; | ||
notifying = require('notifying'); | ||
reactivity = require('reactivity'); | ||
@@ -11,29 +11,64 @@ util = require('./util'); | ||
mab = require('./memoize_and_block'); | ||
mabs = require('./memoize_and_block_scope'); | ||
block = function(async_func) { | ||
return function() { | ||
return (mabs.get(async_func)).apply(null, arguments); | ||
/* | ||
Combinator that transforms a an async function into a pseudo-blocking service. | ||
*/ | ||
block = function(async_func, hasher) { | ||
var f, global_f, resolve; | ||
if (hasher == null) { | ||
hasher = JSON.stringify; | ||
} | ||
global_f = null; | ||
resolve = function() { | ||
if (mabs.defined()) { | ||
return mabs.get(async_func, hasher); | ||
} else { | ||
return global_f != null ? global_f : global_f = mab(async_func, hasher); | ||
} | ||
}; | ||
f = function() { | ||
return resolve().apply(null, arguments); | ||
}; | ||
f.reset = function() { | ||
return resolve().reset(); | ||
}; | ||
return f; | ||
}; | ||
isolate = function(blocked_service) { | ||
return mabs.attach(blocked_service); | ||
}; | ||
/* | ||
f = unblock f | ||
f (err, res, monitor) -> console.log res | ||
*/ | ||
unblock = function(func) { | ||
var f; | ||
f = mabs.attach(function() { | ||
return func.apply(null, arguments); | ||
}); | ||
return function() { | ||
var args, cb, _ref; | ||
_ref = util.args_cb(arguments), args = _ref[0], cb = _ref[1]; | ||
return notifying.subscribe((function() { | ||
return f.apply(null, args); | ||
}), function(e, r, n, stop) { | ||
reactivity.subscribe((function() { | ||
return func.apply(null, args); | ||
}), function(e, r, monitor, stopper) { | ||
if (!Blocking.instance(e)) { | ||
stop(); | ||
return typeof cb === "function" ? cb(e, r, n) : void 0; | ||
stopper(); | ||
return typeof cb === "function" ? cb(e, r, monitor) : void 0; | ||
} | ||
}); | ||
return void 0; | ||
}; | ||
}; | ||
/* | ||
tests to see whether a function is blocked ( working ) | ||
*/ | ||
blocked = function(f) { | ||
@@ -54,2 +89,26 @@ var e; | ||
get = function(f, v) { | ||
var result; | ||
result = void 0; | ||
if (blocked(function() { | ||
return result = f(); | ||
})) { | ||
if (typeof v === 'function') { | ||
return v(); | ||
} else { | ||
return v; | ||
} | ||
} else { | ||
return result; | ||
} | ||
}; | ||
subscribe = function(func, cb) { | ||
return reactivity.subscribe(func, function(e, r, m, s) { | ||
if (!Blocking.instance(e)) { | ||
return cb(e, r, m, s); | ||
} | ||
}); | ||
}; | ||
x = module.exports = block; | ||
@@ -63,4 +122,8 @@ | ||
x.Blocking = Blocking; | ||
x.isolate = isolate; | ||
x.get = get; | ||
x.subscribe = subscribe; | ||
}).call(this); |
@@ -17,9 +17,12 @@ // Generated by CoffeeScript 1.6.3 | ||
m = refmap(); | ||
return st.attach(func, function() { | ||
return st(func, function() { | ||
return m; | ||
}); | ||
}, | ||
get: function(async_func) { | ||
get: function(async_func, hasher) { | ||
var m; | ||
m = st.get(); | ||
if (hasher == null) { | ||
hasher = JSON.stringify; | ||
} | ||
m = st(); | ||
if (m == null) { | ||
@@ -29,4 +32,7 @@ throw new Error('You must run this inside an unblock() context'); | ||
return m.get_or_else(async_func, function() { | ||
return mab(async_func); | ||
return mab(async_func, hasher); | ||
}); | ||
}, | ||
defined: function() { | ||
return st.defined(); | ||
} | ||
@@ -33,0 +39,0 @@ }; |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Blocking, cell, util; | ||
var Blocking, rcell, util; | ||
cell = require('notifying-cell'); | ||
rcell = require('reactive-cell'); | ||
@@ -12,8 +12,18 @@ util = require('./util'); | ||
/* | ||
GC Warning: this memoized version will store results indefinitely | ||
GC Warning: | ||
The memoized version of the function will store results indefinitely | ||
in its internal cache. | ||
This won't be problem if you're scoping function instances properly | ||
and let the native GC take care of disposing it. | ||
You can call F.reset() to clear the cache. | ||
@async_func an async function ( that takes a node-style callback ) | ||
@hasher an optional function that must return a string | ||
it will receive a set of arguments as input | ||
*/ | ||
module.exports = function(f, hasher) { | ||
var cache; | ||
module.exports = function(async_func, hasher) { | ||
var blocked_f, cache; | ||
if (hasher == null) { | ||
@@ -23,28 +33,19 @@ hasher = JSON.stringify; | ||
cache = {}; | ||
return function() { | ||
var args, c, hash; | ||
blocked_f = function() { | ||
var args, _name; | ||
args = util.arr(arguments); | ||
hash = hasher(args); | ||
if ((c = cache[hash]) != null) { | ||
return c(); | ||
} else { | ||
c = cache[hash] = cell(); | ||
return (cache[_name = hasher(args)] != null ? cache[_name = hasher(args)] : cache[_name] = (function() { | ||
var c; | ||
c = rcell(); | ||
c(new Blocking); | ||
args.push(function(e, r) { | ||
if (e != null) { | ||
if (e instanceof Error) { | ||
return c(e); | ||
} else { | ||
return c(new Error(e)); | ||
} | ||
} else { | ||
return c(r); | ||
} | ||
}); | ||
f.apply(null, args); | ||
return c(); | ||
} | ||
util.apply(async_func, args, c.callback); | ||
return c; | ||
})())(); | ||
}; | ||
blocked_f.reset = function() { | ||
return cache = {}; | ||
}; | ||
return blocked_f; | ||
}; | ||
}).call(this); |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var apply, args_cb, arr, concat, delay, hash, run_with_callback; | ||
var apply, args_cb, arr, cast_to_error, concat, delay, get_or_else, hash, run_with_callback; | ||
@@ -52,2 +52,18 @@ arr = function(arrayish) { | ||
cast_to_error = function(x) { | ||
if (e instanceof Error) { | ||
return e; | ||
} else { | ||
return new Error(e); | ||
} | ||
}; | ||
get_or_else = function(obj, key, generator) { | ||
if (key in obj) { | ||
return obj[key]; | ||
} else { | ||
return obj[key] = generator(); | ||
} | ||
}; | ||
module.exports = { | ||
@@ -61,2 +77,4 @@ arr: arr, | ||
run_with_callback: run_with_callback, | ||
cast_to_error: cast_to_error, | ||
get_or_else: get_or_else, | ||
require_func: function(f) { | ||
@@ -70,3 +88,3 @@ var t; | ||
return delay(100, function() { | ||
return cb(null, "Hello " + name + "!"); | ||
return typeof cb === "function" ? cb(null, "Hello " + name) : void 0; | ||
}); | ||
@@ -73,0 +91,0 @@ }, |
{ | ||
"name": "blocking", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -21,7 +21,7 @@ "author": "Aldo Bucchi <aldo.bucchi@gmail.com>", | ||
"dependencies": { | ||
"stackval": "0.0.1", | ||
"refmap": "0.0.3", | ||
"notifying-cell": "0.0.7", | ||
"notifying": "0.0.11" | ||
"stackval": "~0.1.0", | ||
"reactive-cell": "~0.1.1", | ||
"reactivity": "~1.2.2" | ||
} | ||
} |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
8916
8
281
1
31
+ Addedreactive-cell@~0.1.1
+ Addedreactivity@~1.2.2
+ Addedreactive-cell@0.1.2(transitive)
+ Addedreactivity@1.2.21.2.3(transitive)
+ Addedstackval@0.1.0(transitive)
- Removednotifying@0.0.11
- Removednotifying-cell@0.0.7
- Removedstackval@0.0.1(transitive)
Updatedstackval@~0.1.0