arch-stream
Advanced tools
Comparing version 0.0.5 to 0.0.6
# Changelog | ||
## 0.0.6 | ||
Update | ||
## 0.0.5 | ||
@@ -4,0 +8,0 @@ |
@@ -1,12 +0,11 @@ | ||
/*! arch-stream v0.0.5 | (c) 2015, falsandtru | MIT Licence */ | ||
/*! arch-stream v0.0.6 | (c) 2015, falsandtru | MIT Licence */ | ||
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
var tick_1 = _dereq_('./tick'); | ||
var CALLSTACK_MAX_DEPTH = 1e3; | ||
var CAN_BIND = !!Function.prototype.bind; | ||
var Message = (function () { | ||
function Message( | ||
// mutable once without empty value | ||
// immutable after assignment | ||
parent_, | ||
// mutable once | ||
// immutable after assignment | ||
listener_) { | ||
@@ -17,11 +16,9 @@ if (listener_ === void 0) { listener_ = identity; } | ||
this.send = (function (self) { | ||
return function (data, async, depth) { | ||
if (depth === void 0) { depth = 0; } | ||
return function (data, async) { | ||
assert(typeof async === 'boolean' || async === void 0); | ||
if (!async) { | ||
assert(typeof depth === 'number'); | ||
self.trampoline_(data, depth + 1); | ||
self.trampoline_(data); | ||
} | ||
else { | ||
tick_1.default(CAN_BIND ? self.trampoline_.bind(self, data, depth + 1) : function () { return self.trampoline_(data, depth + 1); }); | ||
tick_1.default(CAN_BIND ? self.trampoline_.bind(self, data) : function () { return self.trampoline_(data); }); | ||
} | ||
@@ -43,7 +40,2 @@ return self; | ||
})(this); | ||
this.then = (function (self) { | ||
return function (done, fail) { | ||
return self.recv(done || fail); | ||
}; | ||
})(this); | ||
if (parent_) { | ||
@@ -68,5 +60,5 @@ assert(parent_.child_ === void 0); | ||
}; | ||
Message.prototype.trampoline_ = function (data, depth) { | ||
assert(typeof depth === 'number'); | ||
Message.prototype.trampoline_ = function (data) { | ||
var collection = this.collection_ ? this.collection_ : this.collect_(); | ||
var delayed = false; | ||
for (var i = 0; i < collection.length; i++) { | ||
@@ -79,28 +71,20 @@ var msg = collection[i]; | ||
} | ||
var resume = cascade(msg, data, depth + 1); | ||
var sync = true; | ||
var called = false; | ||
var resume = resume || function () { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.trampoline_(data); | ||
} | ||
}; | ||
result | ||
.then(resume, resume); | ||
sync = false; | ||
break; | ||
if (called) { | ||
continue; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
return; | ||
function cascade(msg, data, depth) { | ||
assert(typeof depth === 'number'); | ||
return function () { | ||
return sync && depth > CALLSTACK_MAX_DEPTH | ||
? void tick_1.default(CAN_BIND ? msg.cascade_.bind(msg, data, 1) : function () { return msg.cascade_(data, 1); }) | ||
: void msg.cascade_(data, sync ? depth + 1 : 1); | ||
}; | ||
} | ||
delayed = true; | ||
}; | ||
Message.prototype.cascade_ = function (data, depth) { | ||
assert(this instanceof Message); | ||
assert(!(data instanceof Message)); | ||
assert(typeof depth === 'number'); | ||
if (this.child_) { | ||
this.child_.send(data, false, depth + 1); | ||
} | ||
return data; | ||
}; | ||
Message.prototype.clone_ = function (msg) { | ||
@@ -122,2 +106,5 @@ return !msg.parent_ | ||
}; | ||
Message.prototype.then = function (done, _) { | ||
return this.recv(done); | ||
}; | ||
return Message; | ||
@@ -134,4 +121,17 @@ })(); | ||
},{"./tick":3}],2:[function(_dereq_,module,exports){ | ||
},{"./tick":4}],2:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
/* tslint:disable:no-unused-variable */ // tslint bug. https://github.com/palantir/tslint/issues/684 | ||
var case_1 = _dereq_('../proxy/case'); | ||
var hook_1 = _dereq_('../proxy/hook'); | ||
var responsibility_1 = _dereq_('../proxy/responsibility'); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = { | ||
Case: case_1.default, | ||
Hook: hook_1.default, | ||
Responsibility: responsibility_1.default | ||
}; | ||
},{"../proxy/case":5,"../proxy/hook":6,"../proxy/responsibility":7}],3:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
var Throttle = (function () { | ||
@@ -191,13 +191,11 @@ function Throttle() { | ||
},{}],3:[function(_dereq_,module,exports){ | ||
},{}],4:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
var IS_NODE = Function("return typeof process === 'object' && typeof window !== 'object'")(); | ||
var CAN_PROMISE = typeof Promise === 'function'; | ||
var Module; | ||
(function (Module) { | ||
Module.queue = IS_NODE ? Function('return fn => void process.nextTick(fn) || fn')() : enqueue; | ||
var Tick; | ||
(function (Tick) { | ||
Tick.queue = enqueue; | ||
var CAN_PROMISE = typeof Promise === 'function'; | ||
var Queue = []; | ||
var promised = false; | ||
var Reservation = 0; | ||
var Delays = [0, 4, 10, 20, 25].reverse(); | ||
var Timers = []; | ||
function enqueue(fn) { | ||
@@ -207,43 +205,35 @@ assert(typeof fn === 'function'); | ||
schedule(); | ||
return fn; | ||
} | ||
function dequeue() { | ||
assert(Timers.length <= Delays.length); | ||
var queue = flush(); | ||
while (queue.length > 0) { | ||
queue.shift()(); | ||
assert(Reservation <= Delays.length); | ||
--Reservation; | ||
schedule(); | ||
var task = Queue.length; | ||
while (task-- > 0) { | ||
Queue.shift()(); | ||
} | ||
} | ||
function flush() { | ||
if (CAN_PROMISE) { | ||
assert(Queue.length > 0); | ||
promised = false; | ||
function schedule() { | ||
if (Queue.length === 0) { | ||
return; | ||
} | ||
else { | ||
assert(Timers.length > 0); | ||
Timers.shift(); | ||
} | ||
var queue = Queue; | ||
Queue = []; | ||
return queue; | ||
} | ||
function schedule() { | ||
assert(Queue.length > 0); | ||
if (CAN_PROMISE) { | ||
if (!promised) { | ||
for (; Reservation <= 1; Reservation++) { | ||
Promise.resolve().then(dequeue); | ||
promised = true; | ||
} | ||
} | ||
else { | ||
for (var i = Timers.length; i < Delays.length; i++) { | ||
Timers.push(setTimeout(dequeue, Delays[i % Delays.length])); | ||
for (; Reservation < Delays.length; Reservation++) { | ||
setTimeout(dequeue, Delays[Reservation % Delays.length]); | ||
} | ||
} | ||
} | ||
})(Module || (Module = {})); | ||
})(Tick || (Tick = {})); | ||
var IS_NODE = Function("return typeof process === 'object' && typeof window !== 'object'")(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = Module.queue; | ||
exports.default = IS_NODE | ||
? Function('return fn => process.nextTick(fn)')() | ||
: Tick.queue; | ||
},{}],4:[function(_dereq_,module,exports){ | ||
},{}],5:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
@@ -274,3 +264,3 @@ function default_1(definition) { | ||
},{}],5:[function(_dereq_,module,exports){ | ||
},{}],6:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
@@ -301,3 +291,3 @@ function default_1(hooks) { | ||
},{}],6:[function(_dereq_,module,exports){ | ||
},{}],7:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
@@ -336,3 +326,3 @@ function default_1() { | ||
},{}],7:[function(_dereq_,module,exports){ | ||
},{}],8:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
@@ -370,3 +360,3 @@ var modular_1 = _dereq_('./modular'); | ||
},{"./modular":8}],8:[function(_dereq_,module,exports){ | ||
},{"./modular":9}],9:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
@@ -378,2 +368,3 @@ var throttle_1 = _dereq_('../lib/throttle'); | ||
var _this = this; | ||
if (count === void 0) { count = 1; } | ||
this.procs = procs; | ||
@@ -446,3 +437,3 @@ this.count = count; | ||
},{"../lib/throttle":2,"../lib/tick":3}],9:[function(_dereq_,module,exports){ | ||
},{"../lib/throttle":3,"../lib/tick":4}],10:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
@@ -453,3 +444,3 @@ var message_1 = _dereq_('../lib/message'); | ||
function ArchStream( | ||
// immutable without empty value | ||
// immutable after assignment | ||
parent_, | ||
@@ -511,18 +502,22 @@ // immutable | ||
},{"../lib/message":1,"./compose":7}],"arch-stream":[function(_dereq_,module,exports){ | ||
},{"../lib/message":1,"./compose":8}],"arch-stream":[function(_dereq_,module,exports){ | ||
"use strict"; | ||
var transform_1 = _dereq_('./stream/transform'); | ||
var message_1 = _dereq_('./lib/message'); | ||
var case_1 = _dereq_('./proxy/case'); | ||
var responsibility_1 = _dereq_('./proxy/responsibility'); | ||
var hook_1 = _dereq_('./proxy/hook'); | ||
var proxy_1 = _dereq_('./lib/proxy'); | ||
var tick_1 = _dereq_('./lib/tick'); | ||
/* TS1.7 | ||
https://github.com/Microsoft/TypeScript/issues/5175 | ||
export default A | ||
export {Msg} | ||
export {Proxy} | ||
export {Tick} | ||
export {ArchStream} | ||
export {Message} | ||
*/ | ||
var Package = { | ||
default: A, | ||
Msg: Msg, | ||
Proxy: { | ||
Case: case_1.default, | ||
Hook: hook_1.default, | ||
Responsibility: responsibility_1.default | ||
}, | ||
Proxy: proxy_1.default, | ||
Tick: tick_1.default, | ||
@@ -546,3 +541,3 @@ ArchStream: transform_1.default, | ||
},{"./lib/message":1,"./lib/tick":3,"./proxy/case":4,"./proxy/hook":5,"./proxy/responsibility":6,"./stream/transform":9}]},{},["arch-stream",1,2,3,4,5,6,7,8,9]); | ||
},{"./lib/message":1,"./lib/proxy":2,"./lib/tick":4,"./stream/transform":10}]},{},["arch-stream",1,2,3,4,5,6,7,8,9,10]); | ||
typeof module === "object" && module && "exports" in module && (module.exports = require("arch-stream")); |
@@ -1,2 +0,2 @@ | ||
/*! arch-stream v0.0.5 | (c) 2015, falsandtru | MIT Licence */ | ||
require=function t(e,r,n){function o(s,u){if(!r[s]){if(!e[s]){var c="function"==typeof require&&require;if(!u&&c)return c(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var a=r[s]={exports:{}};e[s][0].call(a.exports,function(t){var r=e[s][1][t];return o(r?r:t)},a,a.exports,t,e,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(t,e,r){"use strict";function n(t){return t}function o(t){return!!t&&"object"==typeof t&&"then"in t}var i=t("./tick"),s=1e3,u=!!Function.prototype.bind,c=function(){function t(e,r){void 0===r&&(r=n),this.parent_=e,this.listener_=r,this.send=function(t){return function(e,r,n){return void 0===n&&(n=0),assert("boolean"==typeof r||void 0===r),r?i["default"](u?t.trampoline_.bind(t,e,n+1):function(){return t.trampoline_(e,n+1)}):(assert("number"==typeof n),t.trampoline_(e,n+1)),t}}(this),this.recv=function(e){return function(r){assert(e.listener_===n),e.listener_=r,e.collection_=void 0;var o=new t(e);return void 0!==e.memory_&&e.send(e.memory_),o}}(this),this.then=function(t){return function(e,r){return t.recv(e||r)}}(this),e&&(assert(void 0===e.child_),this.parent_.child_=this)}return t.prototype.root=function(){return this.parent_?this.parent_.root():this},t.prototype.collect_=function(){var t=this,e=[];do e.push(t),t=t.child_;while(t);return this.collection_=e,e},t.prototype.trampoline_=function(t,e){function r(t,e,r){return assert("number"==typeof r),function(){return h&&r>s?void i["default"](u?t.cascade_.bind(t,e,1):function(){return t.cascade_(e,1)}):void t.cascade_(e,h?r+1:1)}}assert("number"==typeof e);for(var n=this.collection_?this.collection_:this.collect_(),c=0;c<n.length;c++){var f=n[c];f.memory_=t;var a=f.listener_(t);if(o(a)){var p=r(f,t,e+1),h=!0;a.then(p,p),h=!1;break}}},t.prototype.cascade_=function(e,r){return assert(this instanceof t),assert(!(e instanceof t)),assert("number"==typeof r),this.child_&&this.child_.send(e,!1,r+1),e},t.prototype.clone_=function(e){return e.parent_?new t(this.clone_(e.parent_),e.listener_):new t(void 0,e.listener_)},t.prototype.clone=function(){return this.clone_(this)},t.prototype.connect=function(t){return assert(void 0===this.child_),assert(void 0===t.parent_),assert(this.listener_===n),this.parent_.child_=t,t.parent_=this.parent_,this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=c},{"./tick":3}],2:[function(t,e,r){"use strict";var n=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return this.processing_.push(t),this.resolver_(t),!0;this.queue_.push(t);do this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?this.processing_.splice(e,1):this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],3:[function(t,e,r){"use strict";var n,o=Function("return typeof process === 'object' && typeof window !== 'object'")(),i="function"==typeof Promise;!function(t){function e(t){return assert("function"==typeof t),u.push(t),s(),t}function r(){assert(a.length<=f.length);for(var t=n();t.length>0;)t.shift()()}function n(){i?(assert(u.length>0),c=!1):(assert(a.length>0),a.shift());var t=u;return u=[],t}function s(){if(assert(u.length>0),i)c||(Promise.resolve().then(r),c=!0);else for(var t=a.length;t<f.length;t++)a.push(setTimeout(r,f[t%f.length]))}t.queue=o?Function("return fn => void process.nextTick(fn) || fn")():e;var u=[],c=!1,f=[0,4,10,20,25].reverse(),a=[]}(n||(n={})),Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n.queue},{}],4:[function(t,e,r){"use strict";function n(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return function(e){var r=+o[n(e)];return r>-1&&r<t.length?t[r](e):t}}var r=t.index,n=t.indexer,o=Object.create(null);return r.forEach(function(t,e){return o[t]=e}),function(t){return{pipe:e}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],5:[function(t,e,r){"use strict";function n(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),s(e)}})}var r=t.pre,n=void 0===r?o:r,i=t.post,s=void 0===i?o:i;return function(t){return{pipe:e}}}function o(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],6:[function(t,e,r){"use strict";function n(){function t(t,e){return r.pipe=function(){for(var r=[],n=0;n<arguments.length;n++)r[n-0]=arguments[n];return r.map(function(r){return function(n){return e(n)instanceof t?r(n):r}})},function(t){return o}}function e(t){return function(e){return t(e)}}var r;return function(n){return r={"for":t,pipe:e}}}function o(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],7:[function(t,e,r){"use strict";var n=t("./modular"),o=function(){function t(t){this.procs_=[],t&&this.register_([t])}return t.prototype.register_=function(t){for(var e=this.procs_,r=this.procs_.length,n=t.length;n--;)e[n+r]=t[n]},t.prototype["import"]=function(t){return assert(t.procs.length>0),--t.count<0&&t.throwCountExceededError(),this.register_(t.procs),this},t.prototype["export"]=function(t){return assert(this.procs_.length>0),new n["default"](this.procs_,t)},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{"./modular":8}],8:[function(t,e,r){"use strict";var n=t("../lib/throttle"),o=t("../lib/tick"),i=function(){function t(t,e){var r=this;this.procs=t,this.count=e,assert(t instanceof Array),assert(t.length>0),o["default"](function(t){return 0<r.count&&r.count<1/0&&r.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.throwCountExceededError=function(){throw assert(this.count<0),new Error("Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw assert(0<this.count&&this.count<1/0),this.count=0,new Error("Import and read counts are not deprived.")},t.prototype.flow=function(t,e,r){var o=this;return void 0===e&&(e=1/0),this.flow_=new n["default"],this.flow_.flow(t,e,r),this.flow_.register(function(t){return o.write_(t)}),this},t.prototype.read_=function(t){--this.count<0&&this.throwCountExceededError(),this.compose_(),this.last_.recv(t)},t.prototype.read=function(t){var e=this,r=!1;return this.read_(function(n){e.flow_&&o["default"](function(){return e.flow_.dequeue(n)}),r&&t(n)}),r=!0,this},t.prototype.write_=function(t){this.first_.send(t)},t.prototype.write=function(t){return this.flow_?this.flow_.enqueue(t):this.write_(t),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=i},{"../lib/throttle":2,"../lib/tick":3}],9:[function(t,e,r){"use strict";var n=t("../lib/message"),o=t("./compose"),i=function(){function t(t,e,r){var o=this;void 0===e&&(e=new n["default"]),void 0===r&&(r=[]),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&r.unshift.apply(r,t.proxies_),r.forEach(function(t){return o.proxy(t)})}return t.prototype.proxy_=function(e,r){function n(t){return Array.isArray(t)?t:[t]}assert(this.proxies_.length>0);var o=this.proxies_.filter(function(t){return"function"==typeof t[e]}).reduce(function(t,r){return n(r[e].apply(r,t))},r);return assert(1===o.length),t.prototype.pipe.call(this,o[0])},t.prototype.proxy=function(t){var e=this,r="function"==typeof t?t():t;return this.proxies_.push(r),Object.keys(r).filter(function(t){return"function"==typeof r[t]&&"import"!==t&&"export"!==t}).forEach(function(t){return e[t]=function(){for(var r=[],n=0;n<arguments.length;n++)r[n-0]=arguments[n];return e.proxy_(t,r)}}),this},t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t){return(new o["default"])["import"](t)},t.prototype["export"]=function(t){return new o["default"](this.message_)["export"](t)},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=i},{"../lib/message":1,"./compose":7}],"arch-stream":[function(t,e,r){"use strict";function n(){return new i["default"]}function o(){return new s["default"]}var n,i=t("./stream/transform"),s=t("./lib/message"),u=t("./proxy/case"),c=t("./proxy/responsibility"),f=t("./proxy/hook"),a=t("./lib/tick"),p={"default":n,Msg:o,Proxy:{Case:u["default"],Hook:f["default"],Responsibility:c["default"]},Tick:a["default"],ArchStream:i["default"],Message:s["default"]};!function(t){t.Msg=p.Msg,t.Proxy=p.Proxy,t.Tick=p.Tick}(n||(n={})),e.exports=p},{"./lib/message":1,"./lib/tick":3,"./proxy/case":4,"./proxy/hook":5,"./proxy/responsibility":6,"./stream/transform":9}]},{},["arch-stream",1,2,3,4,5,6,7,8,9]),"object"==typeof module&&module&&"exports"in module&&(module.exports=require("arch-stream")); | ||
/*! arch-stream v0.0.6 | (c) 2015, falsandtru | MIT Licence */ | ||
require=function t(e,r,n){function o(u,s){if(!r[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var p=r[u]={exports:{}};e[u][0].call(p.exports,function(t){var r=e[u][1][t];return o(r?r:t)},p,p.exports,t,e,r,n)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(t,e,r){"use strict";function n(t){return t}function o(t){return!!t&&"object"==typeof t&&"then"in t}var i=t("./tick"),u=!!Function.prototype.bind,s=function(){function t(e,r){void 0===r&&(r=n),this.parent_=e,this.listener_=r,this.send=function(t){return function(e,r){return assert("boolean"==typeof r||void 0===r),r?i["default"](u?t.trampoline_.bind(t,e):function(){return t.trampoline_(e)}):t.trampoline_(e),t}}(this),this.recv=function(e){return function(r){assert(e.listener_===n),e.listener_=r,e.collection_=void 0;var o=new t(e);return void 0!==e.memory_&&e.send(e.memory_),o}}(this),e&&(assert(void 0===e.child_),this.parent_.child_=this)}return t.prototype.root=function(){return this.parent_?this.parent_.root():this},t.prototype.collect_=function(){var t=this,e=[];do e.push(t),t=t.child_;while(t);return this.collection_=e,e},t.prototype.trampoline_=function(t){for(var e=this.collection_?this.collection_:this.collect_(),r=!1,n=0;n<e.length;n++){var i=e[n];i.memory_=t;var u=i.listener_(t);if(o(u)){var s=!1,c=c||function(){s=!0,r&&i.child_&&i.child_.trampoline_(t)};if(u.then(c,c),!s)break}}r=!0},t.prototype.clone_=function(e){return e.parent_?new t(this.clone_(e.parent_),e.listener_):new t(void 0,e.listener_)},t.prototype.clone=function(){return this.clone_(this)},t.prototype.connect=function(t){return assert(void 0===this.child_),assert(void 0===t.parent_),assert(this.listener_===n),this.parent_.child_=t,t.parent_=this.parent_,this},t.prototype.then=function(t,e){return this.recv(t)},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=s},{"./tick":4}],2:[function(t,e,r){"use strict";var n=t("../proxy/case"),o=t("../proxy/hook"),i=t("../proxy/responsibility");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]={Case:n["default"],Hook:o["default"],Responsibility:i["default"]}},{"../proxy/case":5,"../proxy/hook":6,"../proxy/responsibility":7}],3:[function(t,e,r){"use strict";var n=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return this.processing_.push(t),this.resolver_(t),!0;this.queue_.push(t);do this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?this.processing_.splice(e,1):this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],4:[function(t,e,r){"use strict";var n;!function(t){function e(t){assert("function"==typeof t),i.push(t),n()}function r(){assert(u<=s.length),--u,n();for(var t=i.length;t-->0;)i.shift()()}function n(){if(0!==i.length)if(o)for(;1>=u;u++)Promise.resolve().then(r);else for(;u<s.length;u++)setTimeout(r,s[u%s.length])}t.queue=e;var o="function"==typeof Promise,i=[],u=0,s=[0,4,10,20,25].reverse()}(n||(n={}));var o=Function("return typeof process === 'object' && typeof window !== 'object'")();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o?Function("return fn => process.nextTick(fn)")():n.queue},{}],5:[function(t,e,r){"use strict";function n(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return function(e){var r=+o[n(e)];return r>-1&&r<t.length?t[r](e):t}}var r=t.index,n=t.indexer,o=Object.create(null);return r.forEach(function(t,e){return o[t]=e}),function(t){return{pipe:e}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],6:[function(t,e,r){"use strict";function n(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),u(e)}})}var r=t.pre,n=void 0===r?o:r,i=t.post,u=void 0===i?o:i;return function(t){return{pipe:e}}}function o(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],7:[function(t,e,r){"use strict";function n(){function t(t,e){return r.pipe=function(){for(var r=[],n=0;n<arguments.length;n++)r[n-0]=arguments[n];return r.map(function(r){return function(n){return e(n)instanceof t?r(n):r}})},function(t){return o}}function e(t){return function(e){return t(e)}}var r;return function(n){return r={"for":t,pipe:e}}}function o(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],8:[function(t,e,r){"use strict";var n=t("./modular"),o=function(){function t(t){this.procs_=[],t&&this.register_([t])}return t.prototype.register_=function(t){for(var e=this.procs_,r=this.procs_.length,n=t.length;n--;)e[n+r]=t[n]},t.prototype["import"]=function(t){return assert(t.procs.length>0),--t.count<0&&t.throwCountExceededError(),this.register_(t.procs),this},t.prototype["export"]=function(t){return assert(this.procs_.length>0),new n["default"](this.procs_,t)},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{"./modular":9}],9:[function(t,e,r){"use strict";var n=t("../lib/throttle"),o=t("../lib/tick"),i=function(){function t(t,e){var r=this;void 0===e&&(e=1),this.procs=t,this.count=e,assert(t instanceof Array),assert(t.length>0),o["default"](function(t){return 0<r.count&&r.count<1/0&&r.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.throwCountExceededError=function(){throw assert(this.count<0),new Error("Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw assert(0<this.count&&this.count<1/0),this.count=0,new Error("Import and read counts are not deprived.")},t.prototype.flow=function(t,e,r){var o=this;return void 0===e&&(e=1/0),this.flow_=new n["default"],this.flow_.flow(t,e,r),this.flow_.register(function(t){return o.write_(t)}),this},t.prototype.read_=function(t){--this.count<0&&this.throwCountExceededError(),this.compose_(),this.last_.recv(t)},t.prototype.read=function(t){var e=this,r=!1;return this.read_(function(n){e.flow_&&o["default"](function(){return e.flow_.dequeue(n)}),r&&t(n)}),r=!0,this},t.prototype.write_=function(t){this.first_.send(t)},t.prototype.write=function(t){return this.flow_?this.flow_.enqueue(t):this.write_(t),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=i},{"../lib/throttle":3,"../lib/tick":4}],10:[function(t,e,r){"use strict";var n=t("../lib/message"),o=t("./compose"),i=function(){function t(t,e,r){var o=this;void 0===e&&(e=new n["default"]),void 0===r&&(r=[]),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&r.unshift.apply(r,t.proxies_),r.forEach(function(t){return o.proxy(t)})}return t.prototype.proxy_=function(e,r){function n(t){return Array.isArray(t)?t:[t]}assert(this.proxies_.length>0);var o=this.proxies_.filter(function(t){return"function"==typeof t[e]}).reduce(function(t,r){return n(r[e].apply(r,t))},r);return assert(1===o.length),t.prototype.pipe.call(this,o[0])},t.prototype.proxy=function(t){var e=this,r="function"==typeof t?t():t;return this.proxies_.push(r),Object.keys(r).filter(function(t){return"function"==typeof r[t]&&"import"!==t&&"export"!==t}).forEach(function(t){return e[t]=function(){for(var r=[],n=0;n<arguments.length;n++)r[n-0]=arguments[n];return e.proxy_(t,r)}}),this},t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t){return(new o["default"])["import"](t)},t.prototype["export"]=function(t){return new o["default"](this.message_)["export"](t)},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=i},{"../lib/message":1,"./compose":8}],"arch-stream":[function(t,e,r){"use strict";function n(){return new i["default"]}function o(){return new u["default"]}var n,i=t("./stream/transform"),u=t("./lib/message"),s=t("./lib/proxy"),c=t("./lib/tick"),f={"default":n,Msg:o,Proxy:s["default"],Tick:c["default"],ArchStream:i["default"],Message:u["default"]};!function(t){t.Msg=f.Msg,t.Proxy=f.Proxy,t.Tick=f.Tick}(n||(n={})),e.exports=f},{"./lib/message":1,"./lib/proxy":2,"./lib/tick":4,"./stream/transform":10}]},{},["arch-stream",1,2,3,4,5,6,7,8,9,10]),"object"==typeof module&&module&&"exports"in module&&(module.exports=require("arch-stream")); |
@@ -17,8 +17,8 @@ { | ||
"mocha/mocha.d.ts": { | ||
"ref": "a278148f0ec80f2aa9a2ec22f5089308f74dda47" | ||
"ref": "3fc1377ce29dd9670975cb68615edf1b819fc4a5" | ||
}, | ||
"power-assert/power-assert.d.ts": { | ||
"ref": "a278148f0ec80f2aa9a2ec22f5089308f74dda47" | ||
"ref": "3fc1377ce29dd9670975cb68615edf1b819fc4a5" | ||
} | ||
} | ||
} |
@@ -139,4 +139,4 @@ const gulp = require('gulp'); | ||
gulp.task('lint:watch', function () { | ||
gulp.watch(config.ts.source.src, ['ts:source']); | ||
gulp.watch(config.ts.test.src, ['ts:test']); | ||
gulp.watch(config.ts.source.src, ['lint:source']); | ||
gulp.watch(config.ts.test.src, ['lint:test']); | ||
}); | ||
@@ -253,4 +253,3 @@ | ||
shell('npm i'); | ||
del.sync(require('./dtsm.json').bundle); | ||
shell('dtsm update'); | ||
shell('dtsm update --save'); | ||
}); | ||
@@ -257,0 +256,0 @@ |
11
memo.md
@@ -86,6 +86,2 @@ # memo | ||
### 文脈処理 | ||
Promise#thenが成功文脈と失敗文脈を持つように、1つの関数に複数の文脈を混在させずにパラメータの位置ごとに任意の文脈を持たせる。(CaseProxyによるオプション機能) | ||
### コルーチン化 | ||
@@ -105,4 +101,3 @@ | ||
- 同期処理であるため1チェインごとに遅延されるStream APIより1000倍程度高速となる。 | ||
- チェインごとにコールスタックを消費しないためチェイン数を制限しない。 | ||
- Thenable戻り値による同期処理が約250回以上となった場合、処理を遅延してコールスタックを解放する。 | ||
- チェインがコールスタックを消費せずチェイン数の制限がない。 | ||
@@ -222,6 +217,2 @@ ## API | ||
#### #pipe | ||
戻り値でデータを置換する。 | ||
#### #recv | ||
@@ -228,0 +219,0 @@ |
{ | ||
"name": "arch-stream", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Modular stream for domain and data oriented program architecture design.", | ||
@@ -35,6 +35,7 @@ "private": false, | ||
"devDependencies": { | ||
"browser-sync": "^2.9.8", | ||
"browser-sync": "^2.9.11", | ||
"browserify": "^11.2.0", | ||
"browserify-shim": "^3.8.10", | ||
"del": "^2.0.2", | ||
"dtsm": "^0.11.0", | ||
"extend": "^3.0.0", | ||
@@ -48,7 +49,7 @@ "glob": "^5.0.15", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-tslint": "^3.3.0", | ||
"gulp-tslint": "^3.3.1", | ||
"gulp-typescript": "^2.9.2", | ||
"gulp-uglify": "^1.4.1", | ||
"karma": "^0.13.10", | ||
"karma-chrome-launcher": "^0.2.0", | ||
"karma-chrome-launcher": "^0.2.1", | ||
"karma-coverage": "^0.5.2", | ||
@@ -55,0 +56,0 @@ "karma-coveralls": "^1.1.2", |
@@ -9,3 +9,3 @@ # ArchStream | ||
Transport only modular stream for domain and data oriented program architecture design. | ||
Modular stream for domain and data oriented program architecture design. | ||
@@ -29,3 +29,3 @@ ## API | ||
Message and Thenable data cannot send directly. | ||
Thenable data cannot send directly. | ||
@@ -96,4 +96,2 @@ ### Modular stream | ||
#### Custom | ||
### Call order constraints (Type constraint) | ||
@@ -100,0 +98,0 @@ |
var transform_1 = require('./stream/transform'); | ||
var message_1 = require('./lib/message'); | ||
var case_1 = require('./proxy/case'); | ||
var responsibility_1 = require('./proxy/responsibility'); | ||
var hook_1 = require('./proxy/hook'); | ||
var proxy_1 = require('./lib/proxy'); | ||
var tick_1 = require('./lib/tick'); | ||
/* TS1.7 | ||
https://github.com/Microsoft/TypeScript/issues/5175 | ||
export default A | ||
export {Msg} | ||
export {Proxy} | ||
export {Tick} | ||
export {ArchStream} | ||
export {Message} | ||
*/ | ||
var Package = { | ||
default: A, | ||
Msg: Msg, | ||
Proxy: { | ||
Case: case_1.default, | ||
Hook: hook_1.default, | ||
Responsibility: responsibility_1.default | ||
}, | ||
Proxy: proxy_1.default, | ||
Tick: tick_1.default, | ||
@@ -16,0 +20,0 @@ ArchStream: transform_1.default, |
import ArchStream from './stream/transform'; | ||
import Message from './lib/message'; | ||
import CaseProxy from './proxy/case'; | ||
import ResponsibilityProxy from './proxy/responsibility'; | ||
import HookProxy from './proxy/hook'; | ||
import Proxy from './lib/proxy'; | ||
import Tick from './lib/tick'; | ||
/* TS1.7 | ||
https://github.com/Microsoft/TypeScript/issues/5175 | ||
export default A | ||
export {Msg} | ||
export {Proxy} | ||
export {Tick} | ||
export {ArchStream} | ||
export {Message} | ||
*/ | ||
const Package = { | ||
default: A, | ||
Msg: Msg, | ||
Proxy: { | ||
Case: CaseProxy, | ||
Hook: HookProxy, | ||
Responsibility: ResponsibilityProxy | ||
}, | ||
Tick: Tick, | ||
Msg, | ||
Proxy: Proxy, // tslint bug. https://github.com/palantir/tslint/issues/684 | ||
Tick: Tick, // tslint bug. | ||
ArchStream, | ||
@@ -25,5 +30,5 @@ Message | ||
namespace A { | ||
export var Msg = Package.Msg; | ||
export var Proxy = Package.Proxy; | ||
export var Tick = Package.Tick; | ||
export const Msg = Package.Msg; | ||
export const Proxy = Package.Proxy; | ||
export const Tick = Package.Tick; | ||
} | ||
@@ -30,0 +35,0 @@ |
var tick_1 = require('./tick'); | ||
var CALLSTACK_MAX_DEPTH = 1e3; | ||
var CAN_BIND = !!Function.prototype.bind; | ||
var Message = (function () { | ||
function Message( | ||
// mutable once without empty value | ||
// immutable after assignment | ||
parent_, | ||
// mutable once | ||
// immutable after assignment | ||
listener_) { | ||
@@ -14,11 +13,9 @@ if (listener_ === void 0) { listener_ = identity; } | ||
this.send = (function (self) { | ||
return function (data, async, depth) { | ||
if (depth === void 0) { depth = 0; } | ||
return function (data, async) { | ||
assert(typeof async === 'boolean' || async === void 0); | ||
if (!async) { | ||
assert(typeof depth === 'number'); | ||
self.trampoline_(data, depth + 1); | ||
self.trampoline_(data); | ||
} | ||
else { | ||
tick_1.default(CAN_BIND ? self.trampoline_.bind(self, data, depth + 1) : function () { return self.trampoline_(data, depth + 1); }); | ||
tick_1.default(CAN_BIND ? self.trampoline_.bind(self, data) : function () { return self.trampoline_(data); }); | ||
} | ||
@@ -40,7 +37,2 @@ return self; | ||
})(this); | ||
this.then = (function (self) { | ||
return function (done, fail) { | ||
return self.recv(done || fail); | ||
}; | ||
})(this); | ||
if (parent_) { | ||
@@ -65,5 +57,5 @@ assert(parent_.child_ === void 0); | ||
}; | ||
Message.prototype.trampoline_ = function (data, depth) { | ||
assert(typeof depth === 'number'); | ||
Message.prototype.trampoline_ = function (data) { | ||
var collection = this.collection_ ? this.collection_ : this.collect_(); | ||
var delayed = false; | ||
for (var i = 0; i < collection.length; i++) { | ||
@@ -76,28 +68,20 @@ var msg = collection[i]; | ||
} | ||
var resume = cascade(msg, data, depth + 1); | ||
var sync = true; | ||
var called = false; | ||
var resume = resume || function () { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.trampoline_(data); | ||
} | ||
}; | ||
result | ||
.then(resume, resume); | ||
sync = false; | ||
break; | ||
if (called) { | ||
continue; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
return; | ||
function cascade(msg, data, depth) { | ||
assert(typeof depth === 'number'); | ||
return function () { | ||
return sync && depth > CALLSTACK_MAX_DEPTH | ||
? void tick_1.default(CAN_BIND ? msg.cascade_.bind(msg, data, 1) : function () { return msg.cascade_(data, 1); }) | ||
: void msg.cascade_(data, sync ? depth + 1 : 1); | ||
}; | ||
} | ||
delayed = true; | ||
}; | ||
Message.prototype.cascade_ = function (data, depth) { | ||
assert(this instanceof Message); | ||
assert(!(data instanceof Message)); | ||
assert(typeof depth === 'number'); | ||
if (this.child_) { | ||
this.child_.send(data, false, depth + 1); | ||
} | ||
return data; | ||
}; | ||
Message.prototype.clone_ = function (msg) { | ||
@@ -119,2 +103,5 @@ return !msg.parent_ | ||
}; | ||
Message.prototype.then = function (done, _) { | ||
return this.recv(done); | ||
}; | ||
return Message; | ||
@@ -121,0 +108,0 @@ })(); |
@@ -1,12 +0,15 @@ | ||
import { Message as IMessage, ICallback, IThenable } from 'arch-stream'; | ||
import { Message as IMessage, ICallback } from 'arch-stream'; | ||
import Tick from './tick'; | ||
const CALLSTACK_MAX_DEPTH = 1e3; | ||
const CAN_BIND = !!Function.prototype.bind; | ||
export default class Message<T> implements IMessage<T> { | ||
interface IThenable<T> { | ||
then(done: ICallback<T>, fail?: ICallback<T>): IThenable<T>; | ||
} | ||
export default class Message<T> implements IMessage<T>, IThenable<T> { | ||
constructor( | ||
// mutable once without empty value | ||
// immutable after assignment | ||
private parent_?: Message<T>, | ||
// mutable once | ||
// immutable after assignment | ||
private listener_: ICallback<T> = identity | ||
@@ -21,3 +24,3 @@ ) { | ||
private memory_: T; | ||
// mutable once without empty value | ||
// immutable after assignment | ||
private child_: Message<T>; | ||
@@ -32,3 +35,3 @@ public root(): Message<T> { | ||
private collect_(): Message<T>[] { | ||
var target = this, | ||
let target = this, | ||
collection: Message<T>[] = []; | ||
@@ -44,7 +47,7 @@ do { | ||
private trampoline_(data: T, depth: number): void { | ||
assert(typeof depth === 'number'); | ||
private trampoline_(data: T): void { | ||
const collection = this.collection_ ? this.collection_ : this.collect_(); | ||
let delayed = false; | ||
for (let i = 0; i < collection.length; i++) { | ||
const msg = collection[i]; | ||
var msg = collection[i]; | ||
msg.memory_ = <T>data; | ||
@@ -55,30 +58,21 @@ const result = msg.listener_(data); | ||
const resume = cascade(msg, data, depth + 1); | ||
var sync = true; | ||
(<IThenable<void>>result) | ||
var called = false; | ||
var resume = resume || function () { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.trampoline_(data); | ||
} | ||
}; | ||
result | ||
.then(resume, resume); | ||
sync = false; | ||
break; | ||
if (called) { | ||
continue; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
return; | ||
function cascade<T>(msg: Message<T>, data: T, depth: number) { | ||
assert(typeof depth === 'number'); | ||
return (): void => | ||
sync && depth > CALLSTACK_MAX_DEPTH | ||
? void Tick(CAN_BIND ? msg.cascade_.bind(msg, data, 1) : () => msg.cascade_(data, 1)) | ||
: void msg.cascade_(data, sync ? depth + 1 : 1); | ||
} | ||
delayed = true; | ||
} | ||
private cascade_(data: T, depth: number): T { | ||
assert(this instanceof Message); | ||
assert(!(data instanceof Message)); | ||
assert(typeof depth === 'number'); | ||
if (this.child_) { | ||
this.child_.send(data, false, depth + 1); | ||
} | ||
return data; | ||
} | ||
private clone_(msg: Message<T>): Message<T> { | ||
@@ -104,10 +98,9 @@ return !msg.parent_ | ||
public send = ((self: Message<T>) => | ||
function (data: T, async?: boolean, depth: number = 0): Message<T> { | ||
function (data: T, async?: boolean): Message<T> { | ||
assert(typeof async === 'boolean' || async === void 0); | ||
if (!async) { | ||
assert(typeof depth === 'number'); | ||
self.trampoline_(data, depth + 1); | ||
self.trampoline_(data); | ||
} | ||
else { | ||
Tick(CAN_BIND ? self.trampoline_.bind(self, data, depth + 1) : () => self.trampoline_(data, depth + 1)); | ||
Tick(CAN_BIND ? self.trampoline_.bind(self, data) : () => self.trampoline_(data)); | ||
} | ||
@@ -131,7 +124,5 @@ return self; | ||
public then = ((self: Message<T>) => | ||
function (done: ICallback<T>, fail?: ICallback<T>): Message<T> { | ||
return self.recv(done || fail); | ||
} | ||
)(this); | ||
public then(done: ICallback<T>, _?: ICallback<T>): Message<T> { | ||
return this.recv(done); | ||
} | ||
@@ -138,0 +129,0 @@ } |
@@ -1,2 +0,1 @@ | ||
export default class Throttle<T> { | ||
@@ -3,0 +2,0 @@ private queue_: T[] = []; |
@@ -1,10 +0,8 @@ | ||
var IS_NODE = Function("return typeof process === 'object' && typeof window !== 'object'")(); | ||
var CAN_PROMISE = typeof Promise === 'function'; | ||
var Module; | ||
(function (Module) { | ||
Module.queue = IS_NODE ? Function('return fn => void process.nextTick(fn) || fn')() : enqueue; | ||
var Tick; | ||
(function (Tick) { | ||
Tick.queue = enqueue; | ||
var CAN_PROMISE = typeof Promise === 'function'; | ||
var Queue = []; | ||
var promised = false; | ||
var Reservation = 0; | ||
var Delays = [0, 4, 10, 20, 25].reverse(); | ||
var Timers = []; | ||
function enqueue(fn) { | ||
@@ -14,40 +12,32 @@ assert(typeof fn === 'function'); | ||
schedule(); | ||
return fn; | ||
} | ||
function dequeue() { | ||
assert(Timers.length <= Delays.length); | ||
var queue = flush(); | ||
while (queue.length > 0) { | ||
queue.shift()(); | ||
assert(Reservation <= Delays.length); | ||
--Reservation; | ||
schedule(); | ||
var task = Queue.length; | ||
while (task-- > 0) { | ||
Queue.shift()(); | ||
} | ||
} | ||
function flush() { | ||
if (CAN_PROMISE) { | ||
assert(Queue.length > 0); | ||
promised = false; | ||
function schedule() { | ||
if (Queue.length === 0) { | ||
return; | ||
} | ||
else { | ||
assert(Timers.length > 0); | ||
Timers.shift(); | ||
} | ||
var queue = Queue; | ||
Queue = []; | ||
return queue; | ||
} | ||
function schedule() { | ||
assert(Queue.length > 0); | ||
if (CAN_PROMISE) { | ||
if (!promised) { | ||
for (; Reservation <= 1; Reservation++) { | ||
Promise.resolve().then(dequeue); | ||
promised = true; | ||
} | ||
} | ||
else { | ||
for (var i = Timers.length; i < Delays.length; i++) { | ||
Timers.push(setTimeout(dequeue, Delays[i % Delays.length])); | ||
for (; Reservation < Delays.length; Reservation++) { | ||
setTimeout(dequeue, Delays[Reservation % Delays.length]); | ||
} | ||
} | ||
} | ||
})(Module || (Module = {})); | ||
})(Tick || (Tick = {})); | ||
var IS_NODE = Function("return typeof process === 'object' && typeof window !== 'object'")(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = Module.queue; | ||
exports.default = IS_NODE | ||
? Function('return fn => process.nextTick(fn)')() | ||
: Tick.queue; |
@@ -1,53 +0,38 @@ | ||
declare var process: { nextTick: Function }; | ||
declare var Promise: { resolve: () => Promise }; | ||
declare let process: {}; | ||
declare let Promise: { resolve: () => Promise }; | ||
interface Promise { then(done): Promise; } | ||
const IS_NODE = Function("return typeof process === 'object' && typeof window !== 'object'")(); | ||
const CAN_PROMISE = typeof Promise === 'function'; | ||
namespace Tick { | ||
export const queue = enqueue; | ||
namespace Module { | ||
export var queue = IS_NODE ? Function('return fn => void process.nextTick(fn) || fn')() : enqueue; | ||
const CAN_PROMISE = typeof Promise === 'function'; | ||
var Queue: ((...args) => any)[] = []; | ||
var promised = false; | ||
let Queue: ((...args) => any)[] = []; | ||
let Reservation = 0; | ||
const Delays = [0, 4, 10, 20, 25].reverse(); | ||
const Timers: number[] = []; | ||
function enqueue<T extends (_?: void) => any>(fn: T): T { | ||
function enqueue<T extends (_?: void) => any>(fn: T): void { | ||
assert(typeof fn === 'function'); | ||
Queue.push(fn); | ||
schedule(); | ||
return fn; | ||
} | ||
function dequeue(): void { | ||
assert(Timers.length <= Delays.length); | ||
const queue = flush(); | ||
while (queue.length > 0) { | ||
queue.shift()(); | ||
assert(Reservation <= Delays.length); | ||
--Reservation; | ||
schedule(); | ||
let task = Queue.length; | ||
while (task-- > 0) { | ||
Queue.shift()(); | ||
} | ||
} | ||
function flush(): typeof Queue { | ||
if (CAN_PROMISE) { | ||
assert(Queue.length > 0); | ||
promised = false; | ||
} | ||
else { | ||
assert(Timers.length > 0); | ||
Timers.shift(); | ||
} | ||
const queue = Queue; | ||
Queue = []; | ||
return queue; | ||
} | ||
function schedule(): void { | ||
assert(Queue.length > 0); | ||
if (Queue.length === 0) { return; } | ||
if (CAN_PROMISE) { | ||
if (!promised) { | ||
for (; Reservation <= 1; Reservation++) { | ||
Promise.resolve().then(dequeue); | ||
promised = true; | ||
} | ||
} | ||
else { | ||
for (let i = Timers.length; i < Delays.length; i++) { | ||
Timers.push(setTimeout(dequeue, Delays[i % Delays.length])); | ||
for (; Reservation < Delays.length; Reservation++) { | ||
setTimeout(dequeue, Delays[Reservation % Delays.length]); | ||
} | ||
@@ -58,2 +43,5 @@ } | ||
export default Module.queue; | ||
const IS_NODE = Function("return typeof process === 'object' && typeof window !== 'object'")(); | ||
export default IS_NODE | ||
? <typeof Tick.queue>Function('return fn => process.nextTick(fn)')() | ||
: Tick.queue; |
@@ -8,3 +8,3 @@ import { ICallback, IArchTransformStream } from 'arch-stream'; | ||
export default function <T>() { | ||
var proxy; | ||
let proxy; | ||
return <U>(shadow?: IArchTransformStream<T, U>) => proxy = <ResponsibilityProxy<T, U>>{ | ||
@@ -11,0 +11,0 @@ for: define, |
@@ -6,2 +6,3 @@ var throttle_1 = require('../lib/throttle'); | ||
var _this = this; | ||
if (count === void 0) { count = 1; } | ||
this.procs = procs; | ||
@@ -8,0 +9,0 @@ this.count = count; |
@@ -7,3 +7,3 @@ import { IModularStream, IModularWritableStream, IModularReadableStream, ICallback } from 'arch-stream'; | ||
export default class ModularStream<T> implements IModularStream<T>, IModularWritableStream<T>, IModularReadableStream<T> { | ||
constructor(public procs: Message<T>[], public count: number) { | ||
constructor(public procs: Message<T>[], public count: number = 1) { | ||
assert(procs instanceof Array); | ||
@@ -25,3 +25,3 @@ assert(procs.length > 0); | ||
} | ||
public throwCountDeprivedError() { | ||
private throwCountDeprivedError() { | ||
assert(0 < this.count && this.count < Infinity); | ||
@@ -44,3 +44,3 @@ this.count = 0; | ||
public read(callback: ICallback<T>): IModularWritableStream<T> { | ||
var active = false; | ||
let active = false; | ||
this.read_((entity: T) => { | ||
@@ -47,0 +47,0 @@ if (this.flow_) { |
@@ -5,3 +5,3 @@ var message_1 = require('../lib/message'); | ||
function ArchStream( | ||
// immutable without empty value | ||
// immutable after assignment | ||
parent_, | ||
@@ -8,0 +8,0 @@ // immutable |
@@ -11,3 +11,3 @@ import { ArchStream as IArchStream, IArchTransformStream, ICallback } from 'arch-stream'; | ||
constructor( | ||
// immutable without empty value | ||
// immutable after assignment | ||
private parent_?: ArchStream<T>, | ||
@@ -14,0 +14,0 @@ // immutable |
@@ -12,3 +12,3 @@ import A from 'arch-stream'; | ||
add1 = e => ++e.val; | ||
var tmp = sender; | ||
let tmp = sender; | ||
for (let i = 0; i < 1e3; i++) { | ||
@@ -15,0 +15,0 @@ tmp = tmp.recv(add1); |
@@ -14,3 +14,3 @@ import A from 'arch-stream'; | ||
}); | ||
var stm = A<Entity<number>>().proxy(proxy), | ||
let stm = A<Entity<number>>().proxy(proxy), | ||
add1 = e => ++e.val; | ||
@@ -22,3 +22,3 @@ for (let i = 0; i < 1e3; i++) { | ||
const time = timer(); | ||
var mdl = stm | ||
let mdl = stm | ||
.export() | ||
@@ -37,3 +37,3 @@ .read(e => e.val < 1e3 + 1e3 || console.log(`Case: 1k trans chains * 1k data ${time()}ms`) || done()); | ||
}); | ||
var stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
let stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
add1 = A<Entity<number>>().proxy(proxy).pipe(e => ++e.val).export(Infinity); | ||
@@ -45,3 +45,3 @@ for (let i = 0; i < 1e3; i++) { | ||
const time = timer(); | ||
var mdl = stm | ||
let mdl = stm | ||
.export() | ||
@@ -48,0 +48,0 @@ .read(e => e.val < 1e3 + 1e3 || console.log(`Case: 1k imported trans chains * 1k data ${time()}ms`) || done()); |
@@ -10,3 +10,3 @@ import A from 'arch-stream'; | ||
it('trans 1k chains * 1k data', function (done) { | ||
var stm = A<Entity<number>>().pipe(_ => _), | ||
let stm = A<Entity<number>>().pipe(_ => _), | ||
add1 = e => ++e.val; | ||
@@ -18,3 +18,3 @@ for (let i = 0; i < 1e3; i++) { | ||
const time = timer(); | ||
var mdl = stm | ||
let mdl = stm | ||
.export() | ||
@@ -29,3 +29,3 @@ .read(e => e.val < 1e3 + 1e3 || console.log(`Stream: 1k trans chains * 1k data ${time()}ms`) || done()); | ||
it('imported trans 1k chains * 1k data', function (done) { | ||
var stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
let stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
add1 = A<Entity<number>>().pipe(e => ++e.val).export(Infinity); | ||
@@ -37,3 +37,3 @@ for (let i = 0; i < 1e3; i++) { | ||
const time = timer(); | ||
var mdl = stm | ||
let mdl = stm | ||
.export() | ||
@@ -48,3 +48,3 @@ .read(e => e.val < 1e3 + 1e3 || console.log(`Stream: imported 1k trans chains * 1k data ${time()}ms`) || done()); | ||
it('imported 100 flow trans 1k chains * 1k data', function (done) { | ||
var stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
let stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
add1 = A<Entity<number>>().pipe(e => ++e.val).export(Infinity); | ||
@@ -56,3 +56,3 @@ for (let i = 0; i < 1e3; i++) { | ||
const time = timer(); | ||
var mdl = stm | ||
let mdl = stm | ||
.export() | ||
@@ -67,3 +67,3 @@ .flow(1e3).read(e => e.val < 1e3 + 1e3 || console.log(`Stream: imported 100 flow 1k trans chains * 1k data ${time()}ms`) || done()); | ||
it('imported 1k flow trans 1k chains * 1k data', function (done) { | ||
var stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
let stm = A<Entity<number>>().import(A<Entity<number>>().pipe(_ => _).export()), | ||
add1 = A<Entity<number>>().pipe(e => ++e.val).export(Infinity); | ||
@@ -75,3 +75,3 @@ for (let i = 0; i < 1e3; i++) { | ||
const time = timer(); | ||
var mdl = stm | ||
let mdl = stm | ||
.export() | ||
@@ -78,0 +78,0 @@ .flow(1e3).read(e => e.val < 1e3 + 1e3 || console.log(`Stream: imported 1k flow 1k trans chains * 1k data ${time()}ms`) || done()); |
@@ -11,3 +11,3 @@ var arch_stream_1 = require('arch-stream'); | ||
}); | ||
it('trans', function (done) { | ||
it('pipe', function (done) { | ||
arch_stream_1.default() | ||
@@ -70,4 +70,4 @@ .pipe(function (e) { return ++e.val; }) | ||
.read(function (_) { return assert(false); }); | ||
var add1 = astm.export(); | ||
astm.export(Infinity) | ||
var add1 = astm.export(Infinity); | ||
astm.export() | ||
.read(function (_) { return assert(false); }); | ||
@@ -135,22 +135,7 @@ arch_stream_1.default() | ||
arch_stream_1.default().import(stm); | ||
assert(false); | ||
} | ||
catch (e) { | ||
; | ||
done(); | ||
} | ||
done(); | ||
}); | ||
it('export deprive', function (done) { | ||
var stm = arch_stream_1.default().pipe(function (_) { return _; }).export(); | ||
arch_stream_1.Tick(function (_) { | ||
try { | ||
arch_stream_1.default().import(stm); | ||
assert(false); | ||
} | ||
catch (e) { | ||
; | ||
} | ||
done(); | ||
}); | ||
}); | ||
it('throttle', function (done) { | ||
@@ -157,0 +142,0 @@ var async = false; |
@@ -1,2 +0,2 @@ | ||
import A, { Msg, Tick } from 'arch-stream'; | ||
import A, { Msg } from 'arch-stream'; | ||
@@ -17,3 +17,3 @@ interface Entity<T> { | ||
it('trans', function (done) { | ||
it('pipe', function (done) { | ||
A<Entity<number>>() | ||
@@ -80,3 +80,3 @@ .pipe(e => ++e.val) | ||
it('import many', function (done) { | ||
var astm = A<Entity<number>>() | ||
let astm = A<Entity<number>>() | ||
.pipe(e => Msg<number>().send(++e.val, true)); | ||
@@ -86,4 +86,4 @@ | ||
.read(_ => assert(false)); | ||
const add1 = astm.export(); | ||
astm.export(Infinity) | ||
const add1 = astm.export(Infinity); | ||
astm.export() | ||
.read(_ => assert(false)); | ||
@@ -147,3 +147,3 @@ | ||
it('export exeed', function (done) { | ||
var stm = A<void>().pipe(_ => _).export(); | ||
let stm = A<void>().pipe(_ => _).export(); | ||
try { | ||
@@ -157,26 +157,10 @@ A<void>().import(stm); | ||
A<void>().import(stm); | ||
assert(false); | ||
} | ||
catch (e) { | ||
; | ||
done(); | ||
} | ||
done(); | ||
}); | ||
it('export deprive', function (done) { | ||
var stm = A<void>().pipe(_ => _).export(); | ||
Tick(_ => { | ||
try { | ||
A<void>().import(stm); | ||
assert(false); | ||
} | ||
catch (e) { | ||
; | ||
} | ||
done(); | ||
}); | ||
}); | ||
it('throttle', function (done) { | ||
var async = false; | ||
let async = false; | ||
A<Entity<number>>() | ||
@@ -183,0 +167,0 @@ .pipe(e => ++e.val) |
@@ -9,4 +9,4 @@ var arch_stream_1 = require('arch-stream'); | ||
describe('standard', function () { | ||
it('queue', function (done) { | ||
assert(arch_stream_1.Tick(done) === done); | ||
it('return', function (done) { | ||
assert(arch_stream_1.Tick(done) === void 0); | ||
}); | ||
@@ -13,0 +13,0 @@ it('sequence', function (done) { |
@@ -12,8 +12,8 @@ import { Tick } from 'arch-stream'; | ||
describe('standard', function () { | ||
it('queue', function (done) { | ||
assert(Tick(done) === done); | ||
it('return', function (done) { | ||
assert(Tick(done) === void 0); | ||
}); | ||
it('sequence', function (done) { | ||
var cnt = 0; | ||
let cnt = 0; | ||
Tick(_ => ++cnt); | ||
@@ -24,3 +24,3 @@ Tick(_ => assert(cnt === 1) || done()); | ||
it('async', function (done) { | ||
var async = false; | ||
let async = false; | ||
Tick(_ => assert(async === true)); | ||
@@ -32,3 +32,3 @@ Tick(done); | ||
it('grouping', function (done) { | ||
var interrupt = true; | ||
let interrupt = true; | ||
Tick(_ => _); | ||
@@ -35,0 +35,0 @@ setTimeout(_ => interrupt = false, 0); |
@@ -14,4 +14,4 @@ /** | ||
export function Msg<T>(): Message<T> | ||
export var Proxy: Proxy; | ||
export var Tick: Tick; | ||
export const Proxy: Proxy; | ||
export const Tick: Tick; | ||
} | ||
@@ -61,6 +61,2 @@ export function Msg<T>(): Message<T> | ||
export interface IThenable<T> { | ||
then(done: ICallback<T>, fail?: ICallback<T>): IThenable<T>; | ||
} | ||
export class Message<T> { | ||
@@ -72,3 +68,3 @@ send(data: T, async?: boolean): Message<T>; | ||
type Proxy = typeof Proxy; | ||
export var Proxy: { | ||
export const Proxy: { | ||
Case<T>(definition: { index: (string|number)[], indexer: (entity: T) => string|number }): <U>(shadow?: IArchTransformStream<T, U>) => CaseProxy<T, U>; | ||
@@ -91,4 +87,4 @@ Hook<T>(hooks: { pre?: ICallback<T>, post?: ICallback<T> }): <U>(shadow?: IArchTransformStream<T, U>) => HookProxy<T, U>; | ||
type Tick = typeof Tick; | ||
export function Tick<T extends (_?: void) => any>(fn: T): T | ||
export function Tick<T extends (_?: void) => any>(fn: T): void | ||
} |
@@ -12,3 +12,3 @@ // Type definitions for power-assert | ||
declare function assert(value:any, message?:string):void; | ||
declare module assert { | ||
declare namespace assert { | ||
export class AssertionError implements Error { | ||
@@ -66,3 +66,3 @@ name:string; | ||
declare module "power-assert" { | ||
export = assert; | ||
export default assert; | ||
} |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
66
145940
36
3464
136