hyper-chain
Advanced tools
Comparing version
@@ -14,4 +14,17 @@ // Generated by CoffeeScript 1.12.7 | ||
createExecuteContext = function(internal_fns, _callback) { | ||
var _KV_, exe_ctx; | ||
var _KV_, exe_ctx, outCallback; | ||
_KV_ = {}; | ||
outCallback = function(error, exit_status) { | ||
exe_ctx.exit_status = exit_status; | ||
exe_ctx.error = error; | ||
return ASAP(function() { | ||
var cb, ref; | ||
if (!_callback) { | ||
return; | ||
} | ||
ref = [_callback, null], cb = ref[0], _callback = ref[1]; | ||
debug('outcallback', exe_ctx.error, exe_ctx.feedback, exe_ctx); | ||
return cb(exe_ctx.error, exe_ctx.feedback, exe_ctx); | ||
}); | ||
}; | ||
return exe_ctx = { | ||
@@ -46,4 +59,4 @@ error: null, | ||
return _fn(exe_ctx); | ||
} catch (error) { | ||
err = error; | ||
} catch (error1) { | ||
err = error1; | ||
exe_ctx.error = err; | ||
@@ -55,15 +68,18 @@ debug('resume -> catch error', exe_ctx.step_inx, err.toString()); | ||
exit: function(exit_status) { | ||
exe_ctx.exit_status = exit_status; | ||
if (exe_ctx.error) { | ||
exe_ctx.exit_status = 'error'; | ||
} | ||
return ASAP(function() { | ||
var cb, ref; | ||
if (!_callback) { | ||
return; | ||
var _fail, _ok, p; | ||
p = new Promise(function(resolve, reject) { | ||
var task_promise; | ||
if (exe_ctx.error) { | ||
return reject(exe_ctx.error); | ||
} | ||
ref = [_callback, null], cb = ref[0], _callback = ref[1]; | ||
debug('outcallback', exe_ctx.error, exe_ctx.feedback, exe_ctx); | ||
return cb(exe_ctx.error, exe_ctx.feedback, exe_ctx); | ||
task_promise = exe_ctx.getMergedPromise(); | ||
return task_promise.then(resolve, reject); | ||
}); | ||
_ok = function() { | ||
return outCallback(null, exit_status); | ||
}; | ||
_fail = function(error) { | ||
return outCallback(error, 'error'); | ||
}; | ||
return p.then(_ok, _fail); | ||
}, | ||
@@ -70,0 +86,0 @@ recall: function(name) { |
// Generated by CoffeeScript 1.12.7 | ||
var Dynamo, _, debug, exports, hc; | ||
var Dynamo, EventEmitter, FixedDynamo, FlexDynamo, Semaphore, _, debug, exports, hc, | ||
extend = 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; }, | ||
hasProp = {}.hasOwnProperty, | ||
slice = [].slice; | ||
@@ -10,3 +13,5 @@ _ = require('lodash'); | ||
EventEmitter = require('events'); | ||
/* | ||
@@ -16,17 +21,40 @@ 제 1 목적은 능동성을 확보하는것. | ||
Dynamo 는 EventEmitter, Promise와 같은 선상에 있는 능동체이다 | ||
또한 상태, 저장공간을 가진다. | ||
(Reducer와 차이가 먼지 고민하기.. 쩝) | ||
함수의 흐름은 Chain으로 해결한다. <--> 그러면 Dynamo는 무엇인가? | ||
> program = user defined data + user defined operation | ||
> 단순히 데이터인가? 그렇지 않다. Dynamo는 ADT라고 봐야한다. | ||
> 즉 데이터 + 연산의 모임. | ||
> 그런데 기본제공되는, 널리 쓰이는 사례일 뿐이다. 그럼 뭘 구현해야하지? | ||
> 스트림은 OS에 규정된 실체를 다룬다. 파일, 네트워크, 파이프등... | ||
> 체인은 ADT-ADT 내지, 입력데이터 소스 -> 중간/외부 데이터소스로 간다. | ||
> 없는 데이터를 만들수는 없지. 그러니, 정보량을 보존(변환)하거나, 축소할뿐.(Reduce..?) | ||
>> 이거자체가 체인... ah... | ||
> 맥락에 의한 확장도 가능은한데..?(과거 데이터를 이용하는것뿐이지만..) | ||
>> 체인에서 외부 요소를 접근하기로 했지... | ||
>> 그러고보니 par,ser Dynamo자체도 체인으로 정의를 해버렸네.. 흠.. | ||
addChain | ||
removeChain | ||
But 고정된 데이터 저장소,버퍼등 | ||
DFD의 흐름이 아니라 다양한 크기의 저장소에 집중한다. | ||
Dynamo는 하나의 핸들러를 가진다. | ||
> 다수의 핸들러를 상황에 맞춰서운용하면 이미 커스텀 모듈급 | ||
*/ | ||
Dynamo = (function() { | ||
function Dynamo(opt) {} | ||
Dynamo = (function(superClass) { | ||
extend(Dynamo, superClass); | ||
Dynamo.prototype.setCallback = function(ext_fn) { | ||
function Dynamo() { | ||
this.routine = hc(); | ||
} | ||
Dynamo.prototype.setDataHandler = function(ext_fn) { | ||
this.ext_fn = ext_fn; | ||
}; | ||
Dynamo.prototype.fireHook = function(data, callback) { | ||
Dynamo.prototype.doDataHandling = function(data, callback) { | ||
if (this.ext_fn) { | ||
return this.ext_fn(data, callback); | ||
} else { | ||
return callback(null, null); | ||
} | ||
@@ -37,2 +65,115 @@ }; | ||
})(EventEmitter); | ||
Dynamo.Fixed = FixedDynamo = (function(superClass) { | ||
extend(FixedDynamo, superClass); | ||
function FixedDynamo(data1) { | ||
this.data = data1; | ||
FixedDynamo.__super__.constructor.call(this); | ||
this.feedbacks = _.map(this.data, function(d) { | ||
return void 0; | ||
}); | ||
this.errors = _.map(this.data, function(d) { | ||
return void 0; | ||
}); | ||
} | ||
FixedDynamo.prototype.start = function(callback) { | ||
var self; | ||
self = this; | ||
return this.routine({}, function(err) { | ||
return callback(err, self); | ||
}); | ||
}; | ||
return FixedDynamo; | ||
})(Dynamo); | ||
Dynamo.Flex = FlexDynamo = (function(superClass) { | ||
extend(FlexDynamo, superClass); | ||
function FlexDynamo(opt) { | ||
this.opt = opt; | ||
FlexDynamo.__super__.constructor.call(this); | ||
this.queue = []; | ||
this.afterHandling = this.opt.afterHandling; | ||
this.getEvictable = this.opt.getEvictable; | ||
if (this.afterHandling) { | ||
this.afterHandling = (function(_this) { | ||
return function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
return _this.afterHandling.apply(_this, args); | ||
}; | ||
})(this); | ||
} | ||
if (!this.getEvictable) { | ||
throw new Error("getEvictable is required"); | ||
} | ||
if (this.opt.check.put) { | ||
this.on('put', (function(_this) { | ||
return function() { | ||
return _this.check(); | ||
}; | ||
})(this)); | ||
} | ||
} | ||
FlexDynamo.prototype.put = function(data) { | ||
this.queue.push(data); | ||
return this.emit('put', this); | ||
}; | ||
FlexDynamo.prototype.check = function() { | ||
var data; | ||
data = this.getEvictable(this); | ||
if (data) { | ||
return this.doDataHandling(data, this.afterHandling || void 0); | ||
} else { | ||
return this.emit('pending', this); | ||
} | ||
}; | ||
return FlexDynamo; | ||
})(Dynamo); | ||
Semaphore = (function() { | ||
function Semaphore(max) { | ||
this.available = max; | ||
this.queue = []; | ||
} | ||
Semaphore.prototype.enter = function(fn) { | ||
this.queue.push(fn); | ||
return this.runAvailable(); | ||
}; | ||
Semaphore.prototype.leave = function() { | ||
this.available++; | ||
return this.runAvailable(); | ||
}; | ||
Semaphore.prototype.runAvailable = function() { | ||
var fn; | ||
if (this.queue.length === 0) { | ||
return; | ||
} | ||
if (this.available === 0) { | ||
return; | ||
} | ||
this.available--; | ||
fn = this.queue.shift(); | ||
return fn(); | ||
}; | ||
Semaphore.prototype.destroy = function() { | ||
this.available = 0; | ||
return this.queue = []; | ||
}; | ||
return Semaphore; | ||
})(); | ||
@@ -42,16 +183,25 @@ | ||
var d; | ||
d = new Dynamo(); | ||
d.data = data; | ||
d.feedbacks = _.map(data, function(d) { | ||
return void 0; | ||
d = new FixedDynamo(data); | ||
_.forEach(data, function(datum, inx) { | ||
return d.routine.async(inx, function(cur, done) { | ||
return d.doDataHandling(datum, function(err, feedback) { | ||
d.feedbacks[inx] = feedback; | ||
d.errors[inx] = err; | ||
return done(err); | ||
}); | ||
}); | ||
}); | ||
d.errors = _.map(data, function(d) { | ||
return void 0; | ||
}); | ||
d.start = function(callback) { | ||
var chain; | ||
chain = hc(); | ||
_.forEach(data, function(datum, inx) { | ||
return chain.async(inx, function(cur, done) { | ||
return d.fireHook(datum, function(err, feedback) { | ||
d.routine.wait(); | ||
return d; | ||
}; | ||
Dynamo.nPar = Dynamo.nParallel = function(concurrent, data) { | ||
var d, s; | ||
d = new FixedDynamo(data); | ||
s = new Semaphore(concurrent); | ||
_.forEach(data, function(datum, inx) { | ||
return d.routine.async(inx, function(cur, done) { | ||
return s.enter(function() { | ||
return d.doDataHandling(datum, function(err, feedback) { | ||
s.leave(); | ||
d.feedbacks[inx] = feedback; | ||
@@ -63,7 +213,4 @@ d.errors[inx] = err; | ||
}); | ||
chain.wait(); | ||
return chain({}, function(err, f, exe) { | ||
return callback(err, d); | ||
}); | ||
}; | ||
}); | ||
d.routine.wait(); | ||
return d; | ||
@@ -74,31 +221,15 @@ }; | ||
var d; | ||
d = new Dynamo(); | ||
d.data = data; | ||
d.feedbacks = _.map(data, function(d) { | ||
return void 0; | ||
}); | ||
d.errors = _.map(data, function(d) { | ||
return void 0; | ||
}); | ||
d.start = function(callback) { | ||
var chain; | ||
chain = hc(); | ||
_.forEach(data, function(datum, inx) { | ||
chain.async(inx, function(cur, done) { | ||
debug('dynamo.fire', datum); | ||
return d.fireHook(datum, function(err, feedback) { | ||
debug('done a serial', err, feedback); | ||
d.feedbacks[inx] = feedback; | ||
d.errors[inx] = err; | ||
return done(err); | ||
}); | ||
d = new FixedDynamo(data); | ||
_.forEach(data, function(datum, inx) { | ||
d.routine.async(inx, function(cur, done) { | ||
debug('dynamo.fire', datum); | ||
return d.doDataHandling(datum, function(err, feedback) { | ||
debug('done a serial', err, feedback); | ||
d.feedbacks[inx] = feedback; | ||
d.errors[inx] = err; | ||
return done(err); | ||
}); | ||
return chain.wait(); | ||
}); | ||
return chain({}, function(err, f, exe) { | ||
debug('callback', err, f, exe); | ||
debug('return', err, d); | ||
return callback(err, d); | ||
}); | ||
}; | ||
return d.routine.wait(); | ||
}); | ||
return d; | ||
@@ -105,0 +236,0 @@ }; |
@@ -75,4 +75,4 @@ // Generated by CoffeeScript 1.12.7 | ||
opt = { | ||
setter: 'setCallback', | ||
unsetter: 'setCallback' | ||
setter: 'setDataHandler', | ||
unsetter: 'setDataHandler' | ||
}; | ||
@@ -79,0 +79,0 @@ } |
{ | ||
"name": "hyper-chain", | ||
"version": "0.0.6", | ||
"version": "0.0.8", | ||
"description": "function builder for reactive programing. support promise, node-callback and designed for robust error handling. ", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
hyper-chain |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
52711
22.84%10
11.11%840
55.27%0
-100%