@onflow/util-actor
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,4 +5,12 @@ ### Unreleased | ||
### 0.0.2 -- 2020-08-13 | ||
- 2020-08-13 -- Added exported fn `subscriber(address, spawnFn, callback)` | ||
- 2020-08-13 -- Added exported fn `snapshoter(address, spawnFn)` | ||
- 2020-08-13 -- Added `ctx.sendSelf()` | ||
- 2020-08-13 -- Added `ctx.subscriberCount()` | ||
- 2020-08-13 -- Added `ctx.hasSubs()` | ||
### 0.0.1 -- 2020-07-17 | ||
- 2020-07-17 -- Initial Implementation |
@@ -1,2 +0,2 @@ | ||
var t,n=(t=require("queue-microtask"))&&"object"==typeof t&&"default"in t?t.default:t;function e(){return(e=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t}).apply(this,arguments)}function r(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}const o=function(){function t(){}return t.prototype.then=function(n,e){const r=new t,o=this.s;if(o){const t=1&o?n:e;if(t){try{i(r,1,t(this.v))}catch(t){i(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?i(r,1,n?n(o):o):e?i(r,1,e(o)):i(r,2,o)}catch(t){i(r,2,t)}},r},t}();function i(t,n,e){if(!t.s){if(e instanceof o){if(!e.s)return void(e.o=i.bind(null,t,n));1&n&&(n=e.s),e=e.v}if(e&&e.then)return void e.then(i.bind(null,t,n),i.bind(null,t,2));t.s=n,t.v=e;const r=t.o;r&&r(t)}}function u(t){return t instanceof o&&1&t.s}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var c="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;c.FCL_REGISTRY=null==c.FCL_REGISTRY?{}:c.FCL_REGISTRY;var f=0,s=function(t,n,e,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,f=null!=r.timeout?r.timeout:5e3;u&&f&&setTimeout(function(){return i(new Error("Timeout: "+f+"ms passed without a response."))},f);var s={to:t,from:r.from,tag:n,data:e,timeout:f,reply:o,reject:i};try{c.FCL_REGISTRY[t].mailbox.deliver(s),u||o(!0)}catch(t){console.error("FCL.Actor -- Could Not Deliver Message",s,t)}})},l=function(t){delete c.FCL_REGISTRY[t]};exports.EXIT="EXIT",exports.INIT="INIT",exports.SUBSCRIBE="SUBSCRIBE",exports.TERMINATE="TERMINATE",exports.UNSUBSCRIBE="UNSUBSCRIBE",exports.kill=l,exports.send=s,exports.spawn=function(t,a){if(void 0===a&&(a=null),null==a&&(a=++f),null!=c.FCL_REGISTRY[a])return a;var v,d;c.FCL_REGISTRY[a]={addr:a,mailbox:(d=[],{deliver:function(t){try{return d.push(t),v&&(v(d.shift()),v=void 0),Promise.resolve()}catch(t){return Promise.reject(t)}},receive:function(){return new Promise(function(t){var n=d.shift();if(n)return t(n);v=t})}}),subs:new Set,kvs:{}};var h,b={self:function(){return a},receive:function(){return c.FCL_REGISTRY[a].mailbox.receive()},send:function(t,n,e,r){return void 0===r&&(r={}),r.from=a,s(t,n,e,r)},broadcast:function(t,n,e){void 0===e&&(e={}),e.from=a;for(var o,i=function(t,n){var e;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return r(t,void 0);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?r(t,void 0):void 0}}(t))){e&&(t=e);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(e=t[Symbol.iterator]()).next.bind(e)}(c.FCL_REGISTRY[a].subs);!(o=i()).done;)s(o.value,t,n,e)},subscribe:function(t){return null!=t&&c.FCL_REGISTRY[a].subs.add(t)},unsubscribe:function(t){return null!=t&&c.FCL_REGISTRY[a].subs.delete(t)},put:function(t,n){null!=t&&(c.FCL_REGISTRY[a].kvs[t]=n)},get:function(t,n){var e=c.FCL_REGISTRY[a].kvs[t];return null==e?n:e},delete:function(t){delete c.FCL_REGISTRY[a].kvs[t]},update:function(t,n){null!=t&&(c.FCL_REGISTRY[a].kvs[t]=n(c.FCL_REGISTRY[a].kvs[t]))},keys:function(){return Object.keys(c.FCL_REGISTRY[a].kvs)},all:function(){return c.FCL_REGISTRY[a].kvs},where:function(t){return Object.keys(c.FCL_REGISTRY[a].kvs).reduce(function(n,r){var o;return t.test(r)?e({},n,((o={})[r]=c.FCL_REGISTRY[a].kvs[r],o)):n},{})},merge:function(t){void 0===t&&(t={}),Object.keys(t).forEach(function(n){return c.FCL_REGISTRY[a].kvs[n]=t[n]})}};return"object"==typeof t&&(void 0===(h=t)&&(h={}),t=function(t){try{var n=function(){var n=function(t,n,e){for(var r;;){var c=1;if(u(c)&&(c=c.v),!c)return f;if(c.then){r=0;break}var f=e();if(f&&f.then){if(!u(f)){r=1;break}f=f.s}}var s=new o,l=i.bind(null,s,2);return(0===r?c.then(v):1===r?f.then(a):(void 0).then(function(){(c=1)?c.then?c.then(v).then(void 0,l):v(c):i(s,1,f)})).then(void 0,l),s;function a(t){f=t;do{if(!(c=1)||u(c)&&!c.v)return void i(s,1,f);if(c.then)return void c.then(v).then(void 0,l);u(f=e())&&(f=f.v)}while(!f||!f.then);f.then(a).then(void 0,l)}function v(t){t?(f=e())&&f.then?f.then(a).then(void 0,l):a(f):i(s,1,f)}}(0,0,function(){return Promise.resolve(t.receive()).then(function(n){var e=function(e,r){try{var o=function(e,r){try{var o=function(){function e(){return Promise.resolve(h[n.tag](t,n,n.data||{})).then(function(){})}var r=function(){if("EXIT"===n.tag){var e=function(){if("function"==typeof h.TERMINATE)return Promise.resolve(h.TERMINATE(t,n,n.data||{})).then(function(){})}();if(e&&e.then)return e.then(function(){})}}();return r&&r.then?r.then(e):e()}()}catch(t){return r(t)}return o&&o.then?o.then(void 0,r):o}(0,function(e){console.error(t.self()+" Error",n,e)})}catch(t){return}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):void 0}(0,function(t,n){});if(e&&e.then)return e.then(function(){})})});return n&&n.then?n.then(function(){}):void 0},e=function(){if("function"==typeof h.INIT)return Promise.resolve(h.INIT(t)).then(function(){})}();return Promise.resolve(e&&e.then?e.then(n):n())}catch(t){return Promise.reject(t)}}),n(function(){try{return Promise.resolve(t(b)).then(function(){l(a)})}catch(t){return Promise.reject(t)}}),a}; | ||
var n,e=(n=require("queue-microtask"))&&"object"==typeof n&&"default"in n?n.default:n;function t(){return(t=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}function r(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function o(n,e,t){if(!n.s){if(t instanceof i){if(!t.s)return void(t.o=o.bind(null,n,e));1&e&&(e=t.s),t=t.v}if(t&&t.then)return void t.then(o.bind(null,n,e),o.bind(null,n,2));n.s=e,n.v=t;var r=n.o;r&&r(n)}}var i=function(){function n(){}return n.prototype.then=function(e,t){var r=new n,i=this.s;if(i){var u=1&i?e:t;if(u){try{o(r,1,u(this.v))}catch(n){o(r,2,n)}return r}return this}return this.o=function(n){try{var i=n.v;1&n.s?o(r,1,e?e(i):i):t?o(r,1,t(i)):o(r,2,i)}catch(n){o(r,2,n)}},r},n}();function u(n){return n instanceof i&&1&n.s}function c(n,e,t){for(var r;;){var c=n();if(u(c)&&(c=c.v),!c)return f;if(c.then){r=0;break}var f=t();if(f&&f.then){if(!u(f)){r=1;break}f=f.s}if(e){var s=e();if(s&&s.then&&!u(s)){r=2;break}}}var a=new i,l=o.bind(null,a,2);return(0===r?c.then(h):1===r?f.then(v):s.then(d)).then(void 0,l),a;function v(r){f=r;do{if(e&&(s=e())&&s.then&&!u(s))return void s.then(d).then(void 0,l);if(!(c=n())||u(c)&&!c.v)return void o(a,1,f);if(c.then)return void c.then(h).then(void 0,l);u(f=t())&&(f=f.v)}while(!f||!f.then);f.then(v).then(void 0,l)}function h(n){n?(f=t())&&f.then?f.then(v).then(void 0,l):v(f):o(a,1,f)}function d(){(c=n())?c.then?c.then(h).then(void 0,l):h(c):o(a,1,f)}}var f="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;f.FCL_REGISTRY=null==f.FCL_REGISTRY?{}:f.FCL_REGISTRY;var s=0,a=function(n,e,t,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:n,from:r.from,tag:e,data:t,timeout:c,reply:o,reject:i};try{f.FCL_REGISTRY[n].mailbox.deliver(s),u||o(!0)}catch(n){console.error("FCL.Actor -- Could Not Deliver Message",s,n)}})},l=function(n){delete f.FCL_REGISTRY[n]},v=function(n,o){if(void 0===o&&(o=null),null==o&&(o=++s),null!=f.FCL_REGISTRY[o])return o;var i,u;f.FCL_REGISTRY[o]={addr:o,mailbox:(u=[],{deliver:function(n){try{return u.push(n),i&&(i(u.shift()),i=void 0),Promise.resolve()}catch(n){return Promise.reject(n)}},receive:function(){return new Promise(function(n){var e=u.shift();if(e)return n(e);i=n})}}),subs:new Set,kvs:{}};var v,h={self:function(){return o},receive:function(){return f.FCL_REGISTRY[o].mailbox.receive()},send:function(n,e,t,r){return void 0===r&&(r={}),r.from=o,a(n,e,t,r)},sendSelf:function(n,e,t){f.FCL_REGISTRY[o]&&a(o,n,e,t)},broadcast:function(n,e,t){void 0===t&&(t={}),t.from=o;for(var i,u=function(n,e){var t;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(t=function(n,e){if(n){if("string"==typeof n)return r(n,void 0);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?r(n,void 0):void 0}}(n))){t&&(n=t);var o=0;return function(){return o>=n.length?{done:!0}:{done:!1,value:n[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=n[Symbol.iterator]()).next.bind(t)}(f.FCL_REGISTRY[o].subs);!(i=u()).done;)a(i.value,n,e,t)},subscribe:function(n){return null!=n&&f.FCL_REGISTRY[o].subs.add(n)},unsubscribe:function(n){return null!=n&&f.FCL_REGISTRY[o].subs.delete(n)},subscriberCount:function(){return f.FCL_REGISTRY[o].subs.size},hasSubs:function(){return!!f.FCL_REGISTRY[o].subs.size},put:function(n,e){null!=n&&(f.FCL_REGISTRY[o].kvs[n]=e)},get:function(n,e){var t=f.FCL_REGISTRY[o].kvs[n];return null==t?e:t},delete:function(n){delete f.FCL_REGISTRY[o].kvs[n]},update:function(n,e){null!=n&&(f.FCL_REGISTRY[o].kvs[n]=e(f.FCL_REGISTRY[o].kvs[n]))},keys:function(){return Object.keys(f.FCL_REGISTRY[o].kvs)},all:function(){return f.FCL_REGISTRY[o].kvs},where:function(n){return Object.keys(f.FCL_REGISTRY[o].kvs).reduce(function(e,r){var i;return n.test(r)?t({},e,((i={})[r]=f.FCL_REGISTRY[o].kvs[r],i)):e},{})},merge:function(n){void 0===n&&(n={}),Object.keys(n).forEach(function(e){return f.FCL_REGISTRY[o].kvs[e]=n[e]})}};return"object"==typeof n&&(void 0===(v=n)&&(v={}),n=function(n){try{var e=function(){var e=c(function(){return 1},void 0,function(){return Promise.resolve(n.receive()).then(function(e){var t=function(t,r){try{var o=function(t,r){try{var o=function(){function t(){return Promise.resolve(v[e.tag](n,e,e.data||{})).then(function(){})}var r=function(){if("EXIT"===e.tag){var t=function(){if("function"==typeof v.TERMINATE)return Promise.resolve(v.TERMINATE(n,e,e.data||{})).then(function(){})}();if(t&&t.then)return t.then(function(){})}}();return r&&r.then?r.then(t):t()}()}catch(n){return r(n)}return o&&o.then?o.then(void 0,r):o}(0,function(t){console.error(n.self()+" Error",e,t)})}catch(n){return}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):void 0}(0,function(n,e){});if(t&&t.then)return t.then(function(){})})});return e&&e.then?e.then(function(){}):void 0},t=function(){if("function"==typeof v.INIT)return Promise.resolve(v.INIT(n)).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(n){return Promise.reject(n)}}),e(function(){try{return Promise.resolve(n(h)).then(function(){l(o)})}catch(n){return Promise.reject(n)}}),o};exports.EXIT="EXIT",exports.INIT="INIT",exports.SNAPSHOT="SNAPSHOT",exports.SUBSCRIBE="SUBSCRIBE",exports.TERMINATE="TERMINATE",exports.UNSUBSCRIBE="UNSUBSCRIBE",exports.UPDATED="UPDATED",exports.kill=l,exports.send=a,exports.snapshoter=function(n,e){return e(n),a(n,"SNAPSHOT",null,{expectReply:!0,timeout:0})},exports.spawn=v,exports.subscriber=function(n,e,t){e(n);var r=v(function(e){try{var r;return e.send(n,"SUBSCRIBE"),Promise.resolve(c(function(){return!r&&1},void 0,function(){return Promise.resolve(e.receive()).then(function(o){if("@EXIT"===o.tag)return e.send(n,"UNSUBSCRIBE"),void(r=1);t(o.data)})}))}catch(n){return Promise.reject(n)}});return function(){return a(r,"@EXIT")}}; | ||
//# sourceMappingURL=actor.js.map |
@@ -1,2 +0,2 @@ | ||
import n from"queue-microtask";function t(){return(t=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n}).apply(this,arguments)}function e(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}const r=function(){function n(){}return n.prototype.then=function(t,e){const r=new n,i=this.s;if(i){const n=1&i?t:e;if(n){try{o(r,1,n(this.v))}catch(n){o(r,2,n)}return r}return this}return this.o=function(n){try{const i=n.v;1&n.s?o(r,1,t?t(i):i):e?o(r,1,e(i)):o(r,2,i)}catch(n){o(r,2,n)}},r},n}();function o(n,t,e){if(!n.s){if(e instanceof r){if(!e.s)return void(e.o=o.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(o.bind(null,n,t),o.bind(null,n,2));n.s=t,n.v=e;const i=n.o;i&&i(n)}}function i(n){return n instanceof r&&1&n.s}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var u="INIT",c="SUBSCRIBE",f="UNSUBSCRIBE",l="EXIT",s="TERMINATE",a="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;a.FCL_REGISTRY=null==a.FCL_REGISTRY?{}:a.FCL_REGISTRY;var v=0,d=function(n,t,e,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var f={to:n,from:r.from,tag:t,data:e,timeout:c,reply:o,reject:i};try{a.FCL_REGISTRY[n].mailbox.deliver(f),u||o(!0)}catch(n){console.error("FCL.Actor -- Could Not Deliver Message",f,n)}})},h=function(n){delete a.FCL_REGISTRY[n]},b=function(u,c){if(void 0===c&&(c=null),null==c&&(c=++v),null!=a.FCL_REGISTRY[c])return c;var f,l;a.FCL_REGISTRY[c]={addr:c,mailbox:(l=[],{deliver:function(n){try{return l.push(n),f&&(f(l.shift()),f=void 0),Promise.resolve()}catch(n){return Promise.reject(n)}},receive:function(){return new Promise(function(n){var t=l.shift();if(t)return n(t);f=n})}}),subs:new Set,kvs:{}};var s,b={self:function(){return c},receive:function(){return a.FCL_REGISTRY[c].mailbox.receive()},send:function(n,t,e,r){return void 0===r&&(r={}),r.from=c,d(n,t,e,r)},broadcast:function(n,t,r){void 0===r&&(r={}),r.from=c;for(var o,i=function(n,t){var r;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(r=function(n,t){if(n){if("string"==typeof n)return e(n,void 0);var r=Object.prototype.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(n,void 0):void 0}}(n))){r&&(n=r);var o=0;return function(){return o>=n.length?{done:!0}:{done:!1,value:n[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=n[Symbol.iterator]()).next.bind(r)}(a.FCL_REGISTRY[c].subs);!(o=i()).done;)d(o.value,n,t,r)},subscribe:function(n){return null!=n&&a.FCL_REGISTRY[c].subs.add(n)},unsubscribe:function(n){return null!=n&&a.FCL_REGISTRY[c].subs.delete(n)},put:function(n,t){null!=n&&(a.FCL_REGISTRY[c].kvs[n]=t)},get:function(n,t){var e=a.FCL_REGISTRY[c].kvs[n];return null==e?t:e},delete:function(n){delete a.FCL_REGISTRY[c].kvs[n]},update:function(n,t){null!=n&&(a.FCL_REGISTRY[c].kvs[n]=t(a.FCL_REGISTRY[c].kvs[n]))},keys:function(){return Object.keys(a.FCL_REGISTRY[c].kvs)},all:function(){return a.FCL_REGISTRY[c].kvs},where:function(n){return Object.keys(a.FCL_REGISTRY[c].kvs).reduce(function(e,r){var o;return n.test(r)?t({},e,((o={})[r]=a.FCL_REGISTRY[c].kvs[r],o)):e},{})},merge:function(n){void 0===n&&(n={}),Object.keys(n).forEach(function(t){return a.FCL_REGISTRY[c].kvs[t]=n[t]})}};return"object"==typeof u&&(void 0===(s=u)&&(s={}),u=function(n){try{var t=function(){var t=function(n,t,e){for(var u;;){var c=1;if(i(c)&&(c=c.v),!c)return f;if(c.then){u=0;break}var f=e();if(f&&f.then){if(!i(f)){u=1;break}f=f.s}}var l=new r,s=o.bind(null,l,2);return(0===u?c.then(v):1===u?f.then(a):(void 0).then(function(){(c=1)?c.then?c.then(v).then(void 0,s):v(c):o(l,1,f)})).then(void 0,s),l;function a(n){f=n;do{if(!(c=1)||i(c)&&!c.v)return void o(l,1,f);if(c.then)return void c.then(v).then(void 0,s);i(f=e())&&(f=f.v)}while(!f||!f.then);f.then(a).then(void 0,s)}function v(n){n?(f=e())&&f.then?f.then(a).then(void 0,s):a(f):o(l,1,f)}}(0,0,function(){return Promise.resolve(n.receive()).then(function(t){var e=function(e,r){try{var o=function(e,r){try{var o=function(){function e(){return Promise.resolve(s[t.tag](n,t,t.data||{})).then(function(){})}var r=function(){if("EXIT"===t.tag){var e=function(){if("function"==typeof s.TERMINATE)return Promise.resolve(s.TERMINATE(n,t,t.data||{})).then(function(){})}();if(e&&e.then)return e.then(function(){})}}();return r&&r.then?r.then(e):e()}()}catch(n){return r(n)}return o&&o.then?o.then(void 0,r):o}(0,function(e){console.error(n.self()+" Error",t,e)})}catch(n){return}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):void 0}(0,function(n,t){});if(e&&e.then)return e.then(function(){})})});return t&&t.then?t.then(function(){}):void 0},e=function(){if("function"==typeof s.INIT)return Promise.resolve(s.INIT(n)).then(function(){})}();return Promise.resolve(e&&e.then?e.then(t):t())}catch(n){return Promise.reject(n)}}),n(function(){try{return Promise.resolve(u(b)).then(function(){h(c)})}catch(n){return Promise.reject(n)}}),c};export{l as EXIT,u as INIT,c as SUBSCRIBE,s as TERMINATE,f as UNSUBSCRIBE,h as kill,d as send,b as spawn}; | ||
import e from"queue-microtask";const t=()=>{const e=[];var t;return{async deliver(s){e.push(s),t&&(t(e.shift()),t=void 0)},receive:()=>new Promise(function(s){const o=e.shift();if(o)return s(o);t=s})}},s="INIT",o="SUBSCRIBE",r="UNSUBSCRIBE",n="UPDATED",l="SNAPSHOT",R="EXIT",a="TERMINATE",i="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;i.FCL_REGISTRY=null==i.FCL_REGISTRY?{}:i.FCL_REGISTRY;var u=0;const c=(e,t,s,o={})=>new Promise((r,n)=>{const l=o.expectReply||!1,R=null!=o.timeout?o.timeout:5e3;l&&R&&setTimeout(()=>n(new Error(`Timeout: ${R}ms passed without a response.`)),R);const a={to:e,from:o.from,tag:t,data:s,timeout:R,reply:r,reject:n};try{i.FCL_REGISTRY[e].mailbox.deliver(a),l||r(!0)}catch(e){console.error("FCL.Actor -- Could Not Deliver Message",a,e)}}),E=e=>{delete i.FCL_REGISTRY[e]},T=(s,o=null)=>{if(null==o&&(o=++u),null!=i.FCL_REGISTRY[o])return o;i.FCL_REGISTRY[o]={addr:o,mailbox:t(),subs:new Set,kvs:{}};const r={self:()=>o,receive:()=>i.FCL_REGISTRY[o].mailbox.receive(),send:(e,t,s,r={})=>(r.from=o,c(e,t,s,r)),sendSelf:(e,t,s)=>{i.FCL_REGISTRY[o]&&c(o,e,t,s)},broadcast:(e,t,s={})=>{s.from=o;for(let r of i.FCL_REGISTRY[o].subs)c(r,e,t,s)},subscribe:e=>null!=e&&i.FCL_REGISTRY[o].subs.add(e),unsubscribe:e=>null!=e&&i.FCL_REGISTRY[o].subs.delete(e),subscriberCount:()=>i.FCL_REGISTRY[o].subs.size,hasSubs:()=>!!i.FCL_REGISTRY[o].subs.size,put:(e,t)=>{null!=e&&(i.FCL_REGISTRY[o].kvs[e]=t)},get:(e,t)=>{const s=i.FCL_REGISTRY[o].kvs[e];return null==s?t:s},delete:e=>{delete i.FCL_REGISTRY[o].kvs[e]},update:(e,t)=>{null!=e&&(i.FCL_REGISTRY[o].kvs[e]=t(i.FCL_REGISTRY[o].kvs[e]))},keys:()=>Object.keys(i.FCL_REGISTRY[o].kvs),all:()=>i.FCL_REGISTRY[o].kvs,where:e=>Object.keys(i.FCL_REGISTRY[o].kvs).reduce((t,s)=>e.test(s)?{...t,[s]:i.FCL_REGISTRY[o].kvs[s]}:t,{}),merge:(e={})=>{Object.keys(e).forEach(t=>i.FCL_REGISTRY[o].kvs[t]=e[t])}};return"object"==typeof s&&(s=((e={})=>async t=>{"function"==typeof e.INIT&&await e.INIT(t);e:for(;;){const s=await t.receive();try{if("EXIT"===s.tag){"function"==typeof e.TERMINATE&&await e.TERMINATE(t,s,s.data||{});break e}await e[s.tag](t,s,s.data||{})}catch(e){console.error(t.self()+" Error",s,e)}finally{continue e}}})(s)),e(async()=>{await s(r),E(o)}),o};function I(e,t,s){t(e);const o=T(async t=>{for(t.send(e,"SUBSCRIBE");;){const o=await t.receive();if("@EXIT"===o.tag)return void t.send(e,"UNSUBSCRIBE");s(o.data)}});return()=>c(o,"@EXIT")}function S(e,t){return t(e),c(e,"SNAPSHOT",null,{expectReply:!0,timeout:0})}export{R as EXIT,s as INIT,l as SNAPSHOT,o as SUBSCRIBE,a as TERMINATE,r as UNSUBSCRIBE,n as UPDATED,E as kill,c as send,S as snapshoter,T as spawn,I as subscriber}; | ||
//# sourceMappingURL=actor.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import n from"queue-microtask";function t(){return(t=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n}).apply(this,arguments)}function e(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}const r=function(){function n(){}return n.prototype.then=function(t,e){const r=new n,i=this.s;if(i){const n=1&i?t:e;if(n){try{o(r,1,n(this.v))}catch(n){o(r,2,n)}return r}return this}return this.o=function(n){try{const i=n.v;1&n.s?o(r,1,t?t(i):i):e?o(r,1,e(i)):o(r,2,i)}catch(n){o(r,2,n)}},r},n}();function o(n,t,e){if(!n.s){if(e instanceof r){if(!e.s)return void(e.o=o.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(o.bind(null,n,t),o.bind(null,n,2));n.s=t,n.v=e;const i=n.o;i&&i(n)}}function i(n){return n instanceof r&&1&n.s}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var u="INIT",c="SUBSCRIBE",f="UNSUBSCRIBE",l="EXIT",s="TERMINATE",a="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;a.FCL_REGISTRY=null==a.FCL_REGISTRY?{}:a.FCL_REGISTRY;var v=0,d=function(n,t,e,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var f={to:n,from:r.from,tag:t,data:e,timeout:c,reply:o,reject:i};try{a.FCL_REGISTRY[n].mailbox.deliver(f),u||o(!0)}catch(n){console.error("FCL.Actor -- Could Not Deliver Message",f,n)}})},h=function(n){delete a.FCL_REGISTRY[n]},b=function(u,c){if(void 0===c&&(c=null),null==c&&(c=++v),null!=a.FCL_REGISTRY[c])return c;var f,l;a.FCL_REGISTRY[c]={addr:c,mailbox:(l=[],{deliver:function(n){try{return l.push(n),f&&(f(l.shift()),f=void 0),Promise.resolve()}catch(n){return Promise.reject(n)}},receive:function(){return new Promise(function(n){var t=l.shift();if(t)return n(t);f=n})}}),subs:new Set,kvs:{}};var s,b={self:function(){return c},receive:function(){return a.FCL_REGISTRY[c].mailbox.receive()},send:function(n,t,e,r){return void 0===r&&(r={}),r.from=c,d(n,t,e,r)},broadcast:function(n,t,r){void 0===r&&(r={}),r.from=c;for(var o,i=function(n,t){var r;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(r=function(n,t){if(n){if("string"==typeof n)return e(n,void 0);var r=Object.prototype.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(n,void 0):void 0}}(n))){r&&(n=r);var o=0;return function(){return o>=n.length?{done:!0}:{done:!1,value:n[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=n[Symbol.iterator]()).next.bind(r)}(a.FCL_REGISTRY[c].subs);!(o=i()).done;)d(o.value,n,t,r)},subscribe:function(n){return null!=n&&a.FCL_REGISTRY[c].subs.add(n)},unsubscribe:function(n){return null!=n&&a.FCL_REGISTRY[c].subs.delete(n)},put:function(n,t){null!=n&&(a.FCL_REGISTRY[c].kvs[n]=t)},get:function(n,t){var e=a.FCL_REGISTRY[c].kvs[n];return null==e?t:e},delete:function(n){delete a.FCL_REGISTRY[c].kvs[n]},update:function(n,t){null!=n&&(a.FCL_REGISTRY[c].kvs[n]=t(a.FCL_REGISTRY[c].kvs[n]))},keys:function(){return Object.keys(a.FCL_REGISTRY[c].kvs)},all:function(){return a.FCL_REGISTRY[c].kvs},where:function(n){return Object.keys(a.FCL_REGISTRY[c].kvs).reduce(function(e,r){var o;return n.test(r)?t({},e,((o={})[r]=a.FCL_REGISTRY[c].kvs[r],o)):e},{})},merge:function(n){void 0===n&&(n={}),Object.keys(n).forEach(function(t){return a.FCL_REGISTRY[c].kvs[t]=n[t]})}};return"object"==typeof u&&(void 0===(s=u)&&(s={}),u=function(n){try{var t=function(){var t=function(n,t,e){for(var u;;){var c=1;if(i(c)&&(c=c.v),!c)return f;if(c.then){u=0;break}var f=e();if(f&&f.then){if(!i(f)){u=1;break}f=f.s}}var l=new r,s=o.bind(null,l,2);return(0===u?c.then(v):1===u?f.then(a):(void 0).then(function(){(c=1)?c.then?c.then(v).then(void 0,s):v(c):o(l,1,f)})).then(void 0,s),l;function a(n){f=n;do{if(!(c=1)||i(c)&&!c.v)return void o(l,1,f);if(c.then)return void c.then(v).then(void 0,s);i(f=e())&&(f=f.v)}while(!f||!f.then);f.then(a).then(void 0,s)}function v(n){n?(f=e())&&f.then?f.then(a).then(void 0,s):a(f):o(l,1,f)}}(0,0,function(){return Promise.resolve(n.receive()).then(function(t){var e=function(e,r){try{var o=function(e,r){try{var o=function(){function e(){return Promise.resolve(s[t.tag](n,t,t.data||{})).then(function(){})}var r=function(){if("EXIT"===t.tag){var e=function(){if("function"==typeof s.TERMINATE)return Promise.resolve(s.TERMINATE(n,t,t.data||{})).then(function(){})}();if(e&&e.then)return e.then(function(){})}}();return r&&r.then?r.then(e):e()}()}catch(n){return r(n)}return o&&o.then?o.then(void 0,r):o}(0,function(e){console.error(n.self()+" Error",t,e)})}catch(n){return}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):void 0}(0,function(n,t){});if(e&&e.then)return e.then(function(){})})});return t&&t.then?t.then(function(){}):void 0},e=function(){if("function"==typeof s.INIT)return Promise.resolve(s.INIT(n)).then(function(){})}();return Promise.resolve(e&&e.then?e.then(t):t())}catch(n){return Promise.reject(n)}}),n(function(){try{return Promise.resolve(u(b)).then(function(){h(c)})}catch(n){return Promise.reject(n)}}),c};export{l as EXIT,u as INIT,c as SUBSCRIBE,s as TERMINATE,f as UNSUBSCRIBE,h as kill,d as send,b as spawn}; | ||
import n from"queue-microtask";function t(){return(t=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n}).apply(this,arguments)}function e(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}function r(n,t,e){if(!n.s){if(e instanceof o){if(!e.s)return void(e.o=r.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(r.bind(null,n,t),r.bind(null,n,2));n.s=t,n.v=e;var i=n.o;i&&i(n)}}var o=function(){function n(){}return n.prototype.then=function(t,e){var o=new n,i=this.s;if(i){var u=1&i?t:e;if(u){try{r(o,1,u(this.v))}catch(n){r(o,2,n)}return o}return this}return this.o=function(n){try{var i=n.v;1&n.s?r(o,1,t?t(i):i):e?r(o,1,e(i)):r(o,2,i)}catch(n){r(o,2,n)}},o},n}();function i(n){return n instanceof o&&1&n.s}function u(n,t,e){for(var u;;){var c=n();if(i(c)&&(c=c.v),!c)return f;if(c.then){u=0;break}var f=e();if(f&&f.then){if(!i(f)){u=1;break}f=f.s}if(t){var s=t();if(s&&s.then&&!i(s)){u=2;break}}}var a=new o,l=r.bind(null,a,2);return(0===u?c.then(h):1===u?f.then(v):s.then(d)).then(void 0,l),a;function v(o){f=o;do{if(t&&(s=t())&&s.then&&!i(s))return void s.then(d).then(void 0,l);if(!(c=n())||i(c)&&!c.v)return void r(a,1,f);if(c.then)return void c.then(h).then(void 0,l);i(f=e())&&(f=f.v)}while(!f||!f.then);f.then(v).then(void 0,l)}function h(n){n?(f=e())&&f.then?f.then(v).then(void 0,l):v(f):r(a,1,f)}function d(){(c=n())?c.then?c.then(h).then(void 0,l):h(c):r(a,1,f)}}var c="INIT",f="SUBSCRIBE",s="UNSUBSCRIBE",a="UPDATED",l="SNAPSHOT",v="EXIT",h="TERMINATE",d="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;d.FCL_REGISTRY=null==d.FCL_REGISTRY?{}:d.FCL_REGISTRY;var R=0,b=function(n,t,e,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var f={to:n,from:r.from,tag:t,data:e,timeout:c,reply:o,reject:i};try{d.FCL_REGISTRY[n].mailbox.deliver(f),u||o(!0)}catch(n){console.error("FCL.Actor -- Could Not Deliver Message",f,n)}})},S=function(n){delete d.FCL_REGISTRY[n]},m=function(r,o){if(void 0===o&&(o=null),null==o&&(o=++R),null!=d.FCL_REGISTRY[o])return o;var i,c;d.FCL_REGISTRY[o]={addr:o,mailbox:(c=[],{deliver:function(n){try{return c.push(n),i&&(i(c.shift()),i=void 0),Promise.resolve()}catch(n){return Promise.reject(n)}},receive:function(){return new Promise(function(n){var t=c.shift();if(t)return n(t);i=n})}}),subs:new Set,kvs:{}};var f,s={self:function(){return o},receive:function(){return d.FCL_REGISTRY[o].mailbox.receive()},send:function(n,t,e,r){return void 0===r&&(r={}),r.from=o,b(n,t,e,r)},sendSelf:function(n,t,e){d.FCL_REGISTRY[o]&&b(o,n,t,e)},broadcast:function(n,t,r){void 0===r&&(r={}),r.from=o;for(var i,u=function(n,t){var r;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(r=function(n,t){if(n){if("string"==typeof n)return e(n,void 0);var r=Object.prototype.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(n,void 0):void 0}}(n))){r&&(n=r);var o=0;return function(){return o>=n.length?{done:!0}:{done:!1,value:n[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=n[Symbol.iterator]()).next.bind(r)}(d.FCL_REGISTRY[o].subs);!(i=u()).done;)b(i.value,n,t,r)},subscribe:function(n){return null!=n&&d.FCL_REGISTRY[o].subs.add(n)},unsubscribe:function(n){return null!=n&&d.FCL_REGISTRY[o].subs.delete(n)},subscriberCount:function(){return d.FCL_REGISTRY[o].subs.size},hasSubs:function(){return!!d.FCL_REGISTRY[o].subs.size},put:function(n,t){null!=n&&(d.FCL_REGISTRY[o].kvs[n]=t)},get:function(n,t){var e=d.FCL_REGISTRY[o].kvs[n];return null==e?t:e},delete:function(n){delete d.FCL_REGISTRY[o].kvs[n]},update:function(n,t){null!=n&&(d.FCL_REGISTRY[o].kvs[n]=t(d.FCL_REGISTRY[o].kvs[n]))},keys:function(){return Object.keys(d.FCL_REGISTRY[o].kvs)},all:function(){return d.FCL_REGISTRY[o].kvs},where:function(n){return Object.keys(d.FCL_REGISTRY[o].kvs).reduce(function(e,r){var i;return n.test(r)?t({},e,((i={})[r]=d.FCL_REGISTRY[o].kvs[r],i)):e},{})},merge:function(n){void 0===n&&(n={}),Object.keys(n).forEach(function(t){return d.FCL_REGISTRY[o].kvs[t]=n[t]})}};return"object"==typeof r&&(void 0===(f=r)&&(f={}),r=function(n){try{var t=function(){var t=u(function(){return 1},void 0,function(){return Promise.resolve(n.receive()).then(function(t){var e=function(e,r){try{var o=function(e,r){try{var o=function(){function e(){return Promise.resolve(f[t.tag](n,t,t.data||{})).then(function(){})}var r=function(){if("EXIT"===t.tag){var e=function(){if("function"==typeof f.TERMINATE)return Promise.resolve(f.TERMINATE(n,t,t.data||{})).then(function(){})}();if(e&&e.then)return e.then(function(){})}}();return r&&r.then?r.then(e):e()}()}catch(n){return r(n)}return o&&o.then?o.then(void 0,r):o}(0,function(e){console.error(n.self()+" Error",t,e)})}catch(n){return}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):void 0}(0,function(n,t){});if(e&&e.then)return e.then(function(){})})});return t&&t.then?t.then(function(){}):void 0},e=function(){if("function"==typeof f.INIT)return Promise.resolve(f.INIT(n)).then(function(){})}();return Promise.resolve(e&&e.then?e.then(t):t())}catch(n){return Promise.reject(n)}}),n(function(){try{return Promise.resolve(r(s)).then(function(){S(o)})}catch(n){return Promise.reject(n)}}),o};function I(n,t,e){t(n);var r=m(function(t){try{var r;return t.send(n,"SUBSCRIBE"),Promise.resolve(u(function(){return!r&&1},void 0,function(){return Promise.resolve(t.receive()).then(function(o){if("@EXIT"===o.tag)return t.send(n,"UNSUBSCRIBE"),void(r=1);e(o.data)})}))}catch(n){return Promise.reject(n)}});return function(){return b(r,"@EXIT")}}function E(n,t){return t(n),b(n,"SNAPSHOT",null,{expectReply:!0,timeout:0})}export{v as EXIT,c as INIT,l as SNAPSHOT,f as SUBSCRIBE,h as TERMINATE,s as UNSUBSCRIBE,a as UPDATED,S as kill,b as send,E as snapshoter,m as spawn,I as subscriber}; | ||
//# sourceMappingURL=actor.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("queue-microtask")):"function"==typeof define&&define.amd?define(["exports","queue-microtask"],t):t((n=n||self).utilActor={},n.queueMicrotask)}(this,function(n,t){function e(){return(e=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n}).apply(this,arguments)}function r(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;const o=function(){function n(){}return n.prototype.then=function(t,e){const r=new n,o=this.s;if(o){const n=1&o?t:e;if(n){try{i(r,1,n(this.v))}catch(n){i(r,2,n)}return r}return this}return this.o=function(n){try{const o=n.v;1&n.s?i(r,1,t?t(o):o):e?i(r,1,e(o)):i(r,2,o)}catch(n){i(r,2,n)}},r},n}();function i(n,t,e){if(!n.s){if(e instanceof o){if(!e.s)return void(e.o=i.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(i.bind(null,n,t),i.bind(null,n,2));n.s=t,n.v=e;const r=n.o;r&&r(n)}}function u(n){return n instanceof o&&1&n.s}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var c="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;c.FCL_REGISTRY=null==c.FCL_REGISTRY?{}:c.FCL_REGISTRY;var f=0,l=function(n,t,e,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,f=null!=r.timeout?r.timeout:5e3;u&&f&&setTimeout(function(){return i(new Error("Timeout: "+f+"ms passed without a response."))},f);var l={to:n,from:r.from,tag:t,data:e,timeout:f,reply:o,reject:i};try{c.FCL_REGISTRY[n].mailbox.deliver(l),u||o(!0)}catch(n){console.error("FCL.Actor -- Could Not Deliver Message",l,n)}})},s=function(n){delete c.FCL_REGISTRY[n]};n.EXIT="EXIT",n.INIT="INIT",n.SUBSCRIBE="SUBSCRIBE",n.TERMINATE="TERMINATE",n.UNSUBSCRIBE="UNSUBSCRIBE",n.kill=s,n.send=l,n.spawn=function(n,a){if(void 0===a&&(a=null),null==a&&(a=++f),null!=c.FCL_REGISTRY[a])return a;var v,d;c.FCL_REGISTRY[a]={addr:a,mailbox:(d=[],{deliver:function(n){try{return d.push(n),v&&(v(d.shift()),v=void 0),Promise.resolve()}catch(n){return Promise.reject(n)}},receive:function(){return new Promise(function(n){var t=d.shift();if(t)return n(t);v=n})}}),subs:new Set,kvs:{}};var h,y={self:function(){return a},receive:function(){return c.FCL_REGISTRY[a].mailbox.receive()},send:function(n,t,e,r){return void 0===r&&(r={}),r.from=a,l(n,t,e,r)},broadcast:function(n,t,e){void 0===e&&(e={}),e.from=a;for(var o,i=function(n,t){var e;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(e=function(n,t){if(n){if("string"==typeof n)return r(n,void 0);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?r(n,void 0):void 0}}(n))){e&&(n=e);var o=0;return function(){return o>=n.length?{done:!0}:{done:!1,value:n[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(e=n[Symbol.iterator]()).next.bind(e)}(c.FCL_REGISTRY[a].subs);!(o=i()).done;)l(o.value,n,t,e)},subscribe:function(n){return null!=n&&c.FCL_REGISTRY[a].subs.add(n)},unsubscribe:function(n){return null!=n&&c.FCL_REGISTRY[a].subs.delete(n)},put:function(n,t){null!=n&&(c.FCL_REGISTRY[a].kvs[n]=t)},get:function(n,t){var e=c.FCL_REGISTRY[a].kvs[n];return null==e?t:e},delete:function(n){delete c.FCL_REGISTRY[a].kvs[n]},update:function(n,t){null!=n&&(c.FCL_REGISTRY[a].kvs[n]=t(c.FCL_REGISTRY[a].kvs[n]))},keys:function(){return Object.keys(c.FCL_REGISTRY[a].kvs)},all:function(){return c.FCL_REGISTRY[a].kvs},where:function(n){return Object.keys(c.FCL_REGISTRY[a].kvs).reduce(function(t,r){var o;return n.test(r)?e({},t,((o={})[r]=c.FCL_REGISTRY[a].kvs[r],o)):t},{})},merge:function(n){void 0===n&&(n={}),Object.keys(n).forEach(function(t){return c.FCL_REGISTRY[a].kvs[t]=n[t]})}};return"object"==typeof n&&(void 0===(h=n)&&(h={}),n=function(n){try{var t=function(){var t=function(n,t,e){for(var r;;){var c=1;if(u(c)&&(c=c.v),!c)return f;if(c.then){r=0;break}var f=e();if(f&&f.then){if(!u(f)){r=1;break}f=f.s}}var l=new o,s=i.bind(null,l,2);return(0===r?c.then(v):1===r?f.then(a):(void 0).then(function(){(c=1)?c.then?c.then(v).then(void 0,s):v(c):i(l,1,f)})).then(void 0,s),l;function a(n){f=n;do{if(!(c=1)||u(c)&&!c.v)return void i(l,1,f);if(c.then)return void c.then(v).then(void 0,s);u(f=e())&&(f=f.v)}while(!f||!f.then);f.then(a).then(void 0,s)}function v(n){n?(f=e())&&f.then?f.then(a).then(void 0,s):a(f):i(l,1,f)}}(0,0,function(){return Promise.resolve(n.receive()).then(function(t){var e=function(e,r){try{var o=function(e,r){try{var o=function(){function e(){return Promise.resolve(h[t.tag](n,t,t.data||{})).then(function(){})}var r=function(){if("EXIT"===t.tag){var e=function(){if("function"==typeof h.TERMINATE)return Promise.resolve(h.TERMINATE(n,t,t.data||{})).then(function(){})}();if(e&&e.then)return e.then(function(){})}}();return r&&r.then?r.then(e):e()}()}catch(n){return r(n)}return o&&o.then?o.then(void 0,r):o}(0,function(e){console.error(n.self()+" Error",t,e)})}catch(n){return}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):void 0}(0,function(n,t){});if(e&&e.then)return e.then(function(){})})});return t&&t.then?t.then(function(){}):void 0},e=function(){if("function"==typeof h.INIT)return Promise.resolve(h.INIT(n)).then(function(){})}();return Promise.resolve(e&&e.then?e.then(t):t())}catch(n){return Promise.reject(n)}}),t(function(){try{return Promise.resolve(n(y)).then(function(){s(a)})}catch(n){return Promise.reject(n)}}),a}}); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("queue-microtask")):"function"==typeof define&&define.amd?define(["exports","queue-microtask"],e):e((n=n||self).utilActor={},n.queueMicrotask)}(this,function(n,e){function t(){return(t=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}function r(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function o(n,e,t){if(!n.s){if(t instanceof i){if(!t.s)return void(t.o=o.bind(null,n,e));1&e&&(e=t.s),t=t.v}if(t&&t.then)return void t.then(o.bind(null,n,e),o.bind(null,n,2));n.s=e,n.v=t;var r=n.o;r&&r(n)}}e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var i=function(){function n(){}return n.prototype.then=function(e,t){var r=new n,i=this.s;if(i){var u=1&i?e:t;if(u){try{o(r,1,u(this.v))}catch(n){o(r,2,n)}return r}return this}return this.o=function(n){try{var i=n.v;1&n.s?o(r,1,e?e(i):i):t?o(r,1,t(i)):o(r,2,i)}catch(n){o(r,2,n)}},r},n}();function u(n){return n instanceof i&&1&n.s}function c(n,e,t){for(var r;;){var c=n();if(u(c)&&(c=c.v),!c)return f;if(c.then){r=0;break}var f=t();if(f&&f.then){if(!u(f)){r=1;break}f=f.s}if(e){var s=e();if(s&&s.then&&!u(s)){r=2;break}}}var a=new i,l=o.bind(null,a,2);return(0===r?c.then(d):1===r?f.then(v):s.then(h)).then(void 0,l),a;function v(r){f=r;do{if(e&&(s=e())&&s.then&&!u(s))return void s.then(h).then(void 0,l);if(!(c=n())||u(c)&&!c.v)return void o(a,1,f);if(c.then)return void c.then(d).then(void 0,l);u(f=t())&&(f=f.v)}while(!f||!f.then);f.then(v).then(void 0,l)}function d(n){n?(f=t())&&f.then?f.then(v).then(void 0,l):v(f):o(a,1,f)}function h(){(c=n())?c.then?c.then(d).then(void 0,l):d(c):o(a,1,f)}}var f="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||"object"==typeof window&&window.window===window&&window;f.FCL_REGISTRY=null==f.FCL_REGISTRY?{}:f.FCL_REGISTRY;var s=0,a=function(n,e,t,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:n,from:r.from,tag:e,data:t,timeout:c,reply:o,reject:i};try{f.FCL_REGISTRY[n].mailbox.deliver(s),u||o(!0)}catch(n){console.error("FCL.Actor -- Could Not Deliver Message",s,n)}})},l=function(n){delete f.FCL_REGISTRY[n]},v=function(n,o){if(void 0===o&&(o=null),null==o&&(o=++s),null!=f.FCL_REGISTRY[o])return o;var i,u;f.FCL_REGISTRY[o]={addr:o,mailbox:(u=[],{deliver:function(n){try{return u.push(n),i&&(i(u.shift()),i=void 0),Promise.resolve()}catch(n){return Promise.reject(n)}},receive:function(){return new Promise(function(n){var e=u.shift();if(e)return n(e);i=n})}}),subs:new Set,kvs:{}};var v,d={self:function(){return o},receive:function(){return f.FCL_REGISTRY[o].mailbox.receive()},send:function(n,e,t,r){return void 0===r&&(r={}),r.from=o,a(n,e,t,r)},sendSelf:function(n,e,t){f.FCL_REGISTRY[o]&&a(o,n,e,t)},broadcast:function(n,e,t){void 0===t&&(t={}),t.from=o;for(var i,u=function(n,e){var t;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(t=function(n,e){if(n){if("string"==typeof n)return r(n,void 0);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?r(n,void 0):void 0}}(n))){t&&(n=t);var o=0;return function(){return o>=n.length?{done:!0}:{done:!1,value:n[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=n[Symbol.iterator]()).next.bind(t)}(f.FCL_REGISTRY[o].subs);!(i=u()).done;)a(i.value,n,e,t)},subscribe:function(n){return null!=n&&f.FCL_REGISTRY[o].subs.add(n)},unsubscribe:function(n){return null!=n&&f.FCL_REGISTRY[o].subs.delete(n)},subscriberCount:function(){return f.FCL_REGISTRY[o].subs.size},hasSubs:function(){return!!f.FCL_REGISTRY[o].subs.size},put:function(n,e){null!=n&&(f.FCL_REGISTRY[o].kvs[n]=e)},get:function(n,e){var t=f.FCL_REGISTRY[o].kvs[n];return null==t?e:t},delete:function(n){delete f.FCL_REGISTRY[o].kvs[n]},update:function(n,e){null!=n&&(f.FCL_REGISTRY[o].kvs[n]=e(f.FCL_REGISTRY[o].kvs[n]))},keys:function(){return Object.keys(f.FCL_REGISTRY[o].kvs)},all:function(){return f.FCL_REGISTRY[o].kvs},where:function(n){return Object.keys(f.FCL_REGISTRY[o].kvs).reduce(function(e,r){var i;return n.test(r)?t({},e,((i={})[r]=f.FCL_REGISTRY[o].kvs[r],i)):e},{})},merge:function(n){void 0===n&&(n={}),Object.keys(n).forEach(function(e){return f.FCL_REGISTRY[o].kvs[e]=n[e]})}};return"object"==typeof n&&(void 0===(v=n)&&(v={}),n=function(n){try{var e=function(){var e=c(function(){return 1},void 0,function(){return Promise.resolve(n.receive()).then(function(e){var t=function(t,r){try{var o=function(t,r){try{var o=function(){function t(){return Promise.resolve(v[e.tag](n,e,e.data||{})).then(function(){})}var r=function(){if("EXIT"===e.tag){var t=function(){if("function"==typeof v.TERMINATE)return Promise.resolve(v.TERMINATE(n,e,e.data||{})).then(function(){})}();if(t&&t.then)return t.then(function(){})}}();return r&&r.then?r.then(t):t()}()}catch(n){return r(n)}return o&&o.then?o.then(void 0,r):o}(0,function(t){console.error(n.self()+" Error",e,t)})}catch(n){return}return o&&o.then?o.then(r.bind(null,!1),r.bind(null,!0)):void 0}(0,function(n,e){});if(t&&t.then)return t.then(function(){})})});return e&&e.then?e.then(function(){}):void 0},t=function(){if("function"==typeof v.INIT)return Promise.resolve(v.INIT(n)).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(n){return Promise.reject(n)}}),e(function(){try{return Promise.resolve(n(d)).then(function(){l(o)})}catch(n){return Promise.reject(n)}}),o};n.EXIT="EXIT",n.INIT="INIT",n.SNAPSHOT="SNAPSHOT",n.SUBSCRIBE="SUBSCRIBE",n.TERMINATE="TERMINATE",n.UNSUBSCRIBE="UNSUBSCRIBE",n.UPDATED="UPDATED",n.kill=l,n.send=a,n.snapshoter=function(n,e){return e(n),a(n,"SNAPSHOT",null,{expectReply:!0,timeout:0})},n.spawn=v,n.subscriber=function(n,e,t){e(n);var r=v(function(e){try{var r;return e.send(n,"SUBSCRIBE"),Promise.resolve(c(function(){return!r&&1},void 0,function(){return Promise.resolve(e.receive()).then(function(o){if("@EXIT"===o.tag)return e.send(n,"UNSUBSCRIBE"),void(r=1);t(o.data)})}))}catch(n){return Promise.reject(n)}});return function(){return a(r,"@EXIT")}}}); | ||
//# sourceMappingURL=actor.umd.js.map |
{ | ||
"name": "@onflow/util-actor", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A mechanism for forcing order/transitions of scoped async state", | ||
@@ -21,5 +21,5 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"jest": "25.3.0", | ||
"jest": "26.4.0", | ||
"jest-esm-transformer": "1.0.0", | ||
"microbundle": "0.12.0-next.8" | ||
"microbundle": "0.12.3" | ||
}, | ||
@@ -26,0 +26,0 @@ "dependencies": { |
@@ -7,2 +7,4 @@ import {mailbox as createMailbox} from "./mailbox" | ||
export const UNSUBSCRIBE = "UNSUBSCRIBE" | ||
export const UPDATED = "UPDATED" | ||
export const SNAPSHOT = "SNAPSHOT" | ||
export const EXIT = "EXIT" | ||
@@ -94,2 +96,5 @@ export const TERMINATE = "TERMINATE" | ||
}, | ||
sendSelf: (tag, data, opts) => { | ||
if (root.FCL_REGISTRY[addr]) send(addr, tag, data, opts) | ||
}, | ||
broadcast: (tag, data, opts = {}) => { | ||
@@ -101,2 +106,4 @@ opts.from = addr | ||
unsubscribe: sub => sub != null && root.FCL_REGISTRY[addr].subs.delete(sub), | ||
subscriberCount: () => root.FCL_REGISTRY[addr].subs.size, | ||
hasSubs: () => !!root.FCL_REGISTRY[addr].subs.size, | ||
put: (key, value) => { | ||
@@ -145,1 +152,38 @@ if (key != null) root.FCL_REGISTRY[addr].kvs[key] = value | ||
} | ||
// Returns an unsubscribe function | ||
// A SUBSCRIBE handler will need to be created to handle the subscription event | ||
// | ||
// [SUBSCRIBE]: (ctx, letter) => { | ||
// ctx.subscribe(letter.from) | ||
// ctx.send(letter.from, UPDATED, ctx.all()) | ||
// } | ||
// | ||
export function subscriber(address, spawnFn, callback) { | ||
spawnFn(address) | ||
const EXIT = "@EXIT" | ||
const self = spawn(async ctx => { | ||
ctx.send(address, SUBSCRIBE) | ||
while (1) { | ||
const letter = await ctx.receive() | ||
if (letter.tag === EXIT) { | ||
ctx.send(address, UNSUBSCRIBE) | ||
return | ||
} | ||
callback(letter.data) | ||
} | ||
}) | ||
return () => send(self, EXIT) | ||
} | ||
// Returns a promise that returns a result | ||
// A SNAPSHOT handler will need to be created to handle the snapshot event | ||
// | ||
// [SNAPSHOT]: (ctx, letter) => { | ||
// letter.reply(ctx.all()) | ||
// } | ||
// | ||
export function snapshoter(address, spawnFn) { | ||
spawnFn(address) | ||
return send(address, SNAPSHOT, null, {expectReply: true, timeout: 0}) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
441
82034