@onflow/util-actor
Advanced tools
Comparing version 1.2.0-alpha.2 to 1.2.0-alpha.3
# @onflow/util-actor | ||
## 1.2.0-alpha.3 | ||
### Patch Changes | ||
- [#1663](https://github.com/onflow/fcl-js/pull/1663) [`62dfafa9`](https://github.com/onflow/fcl-js/commit/62dfafa9c7adc3933822b0d3171d6eb025f1719e) Thanks [@nialexsan](https://github.com/nialexsan)! - Upgrade jest to v29.5 and update tests accordingly. Change build to transpile with ESM modules. | ||
## 1.2.0-alpha.2 | ||
@@ -4,0 +10,0 @@ |
@@ -5,8 +5,2 @@ 'use strict'; | ||
var _defineProperty = require('@babel/runtime/helpers/defineProperty'); | ||
var _objectSpread = require('@babel/runtime/helpers/objectSpread2'); | ||
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper'); | ||
var _regeneratorRuntime = require('@babel/runtime/helpers/regeneratorRuntime'); | ||
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator'); | ||
var _typeof = require('@babel/runtime/helpers/typeof'); | ||
var queueMicrotask = require('queue-microtask'); | ||
@@ -16,34 +10,20 @@ | ||
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); | ||
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread); | ||
var _createForOfIteratorHelper__default = /*#__PURE__*/_interopDefaultLegacy(_createForOfIteratorHelper); | ||
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime); | ||
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator); | ||
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); | ||
var queueMicrotask__default = /*#__PURE__*/_interopDefaultLegacy(queueMicrotask); | ||
var mailbox = function mailbox() { | ||
var queue = []; | ||
const mailbox = () => { | ||
const queue = []; | ||
var next; | ||
return { | ||
deliver: function deliver(msg) { | ||
return _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"]().mark(function _callee() { | ||
return _regeneratorRuntime__default["default"]().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
}))(); | ||
async deliver(msg) { | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
}, | ||
receive: function receive() { | ||
receive() { | ||
return new Promise(function innerReceive(resolve) { | ||
var msg = queue.shift(); | ||
const msg = queue.shift(); | ||
if (msg) return resolve(msg); | ||
@@ -53,35 +33,37 @@ next = resolve; | ||
} | ||
}; | ||
}; | ||
var INIT = "INIT"; | ||
var SUBSCRIBE = "SUBSCRIBE"; | ||
var UNSUBSCRIBE = "UNSUBSCRIBE"; | ||
var UPDATED = "UPDATED"; | ||
var SNAPSHOT = "SNAPSHOT"; | ||
var EXIT = "EXIT"; | ||
var TERMINATE = "TERMINATE"; | ||
var root = (typeof self === "undefined" ? "undefined" : _typeof__default["default"](self)) === "object" && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof__default["default"](global)) === "object" && global.global === global && global || (typeof window === "undefined" ? "undefined" : _typeof__default["default"](window)) === "object" && window.window === window && window; | ||
const INIT = "INIT"; | ||
const SUBSCRIBE = "SUBSCRIBE"; | ||
const UNSUBSCRIBE = "UNSUBSCRIBE"; | ||
const UPDATED = "UPDATED"; | ||
const SNAPSHOT = "SNAPSHOT"; | ||
const EXIT = "EXIT"; | ||
const TERMINATE = "TERMINATE"; | ||
const root = typeof self === "object" && self.self === self && self || typeof global === "object" && global.global === global && global || typeof window === "object" && window.window === window && window; | ||
root.FCL_REGISTRY = root.FCL_REGISTRY == null ? {} : root.FCL_REGISTRY; | ||
var pid = 0; | ||
var DEFAULT_TIMEOUT = 5000; | ||
var _send = function send(addr, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise(function (reply, reject) { | ||
var expectReply = opts.expectReply || false; | ||
var timeout = opts.timeout != null ? opts.timeout : DEFAULT_TIMEOUT; | ||
var pid = 0b0; | ||
const DEFAULT_TIMEOUT = 5000; | ||
const send = function (addr, tag, data) { | ||
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise((reply, reject) => { | ||
const expectReply = opts.expectReply || false; | ||
const timeout = opts.timeout != null ? opts.timeout : DEFAULT_TIMEOUT; | ||
if (expectReply && timeout) { | ||
setTimeout(function () { | ||
return reject(new Error("Timeout: ".concat(timeout, "ms passed without a response."))); | ||
}, timeout); | ||
setTimeout(() => reject(new Error(`Timeout: ${timeout}ms passed without a response.`)), timeout); | ||
} | ||
var payload = { | ||
const payload = { | ||
to: addr, | ||
from: opts.from, | ||
tag: tag, | ||
data: data, | ||
timeout: timeout, | ||
reply: reply, | ||
reject: reject | ||
tag, | ||
data, | ||
timeout, | ||
reply, | ||
reject | ||
}; | ||
try { | ||
@@ -95,70 +77,39 @@ root.FCL_REGISTRY[addr] && root.FCL_REGISTRY[addr].mailbox.deliver(payload); | ||
}; | ||
var kill = function kill(addr) { | ||
const kill = addr => { | ||
delete root.FCL_REGISTRY[addr]; | ||
}; | ||
var fromHandlers = function fromHandlers() { | ||
var handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"]().mark(function _callee(ctx) { | ||
var letter; | ||
return _regeneratorRuntime__default["default"]().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(typeof handlers[INIT] === "function")) { | ||
_context.next = 3; | ||
break; | ||
} | ||
_context.next = 3; | ||
return handlers[INIT](ctx); | ||
case 3: | ||
_context.next = 6; | ||
return ctx.receive(); | ||
case 6: | ||
letter = _context.sent; | ||
_context.prev = 7; | ||
if (!(letter.tag === EXIT)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
if (!(typeof handlers[TERMINATE] === "function")) { | ||
_context.next = 12; | ||
break; | ||
} | ||
_context.next = 12; | ||
return handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
case 12: | ||
return _context.abrupt("break", 25); | ||
case 13: | ||
_context.next = 15; | ||
return handlers[letter.tag](ctx, letter, letter.data || {}); | ||
case 15: | ||
_context.next = 20; | ||
break; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context["catch"](7); | ||
console.error("".concat(ctx.self(), " Error"), letter, _context.t0); | ||
case 20: | ||
_context.prev = 20; | ||
return _context.abrupt("continue", 3); | ||
case 23: | ||
_context.next = 3; | ||
break; | ||
case 25: | ||
case "end": | ||
return _context.stop(); | ||
const fromHandlers = function () { | ||
let handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return async ctx => { | ||
if (typeof handlers[INIT] === "function") await handlers[INIT](ctx); | ||
__loop: while (1) { | ||
const letter = await ctx.receive(); | ||
try { | ||
if (letter.tag === EXIT) { | ||
if (typeof handlers[TERMINATE] === "function") { | ||
await handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
} | ||
break __loop; | ||
} | ||
}, _callee, null, [[7, 17, 20, 23]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
await handlers[letter.tag](ctx, letter, letter.data || {}); | ||
} catch (error) { | ||
console.error(`${ctx.self()} Error`, letter, error); | ||
} finally { | ||
continue __loop; | ||
} | ||
} | ||
}; | ||
}; | ||
var spawn = function spawn(fn) { | ||
var addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
const spawn = function (fn) { | ||
let addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (addr == null) addr = ++pid; | ||
if (root.FCL_REGISTRY[addr] != null) return addr; | ||
root.FCL_REGISTRY[addr] = { | ||
addr: addr, | ||
addr, | ||
mailbox: mailbox(), | ||
@@ -169,110 +120,66 @@ subs: new Set(), | ||
}; | ||
var ctx = { | ||
self: function self() { | ||
return addr; | ||
}, | ||
receive: function receive() { | ||
return root.FCL_REGISTRY[addr].mailbox.receive(); | ||
}, | ||
send: function send(to, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
const ctx = { | ||
self: () => addr, | ||
receive: () => root.FCL_REGISTRY[addr].mailbox.receive(), | ||
send: function (to, tag, data) { | ||
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
opts.from = addr; | ||
return _send(to, tag, data, opts); | ||
return send(to, tag, data, opts); | ||
}, | ||
sendSelf: function sendSelf(tag, data, opts) { | ||
if (root.FCL_REGISTRY[addr]) _send(addr, tag, data, opts); | ||
sendSelf: (tag, data, opts) => { | ||
if (root.FCL_REGISTRY[addr]) send(addr, tag, data, opts); | ||
}, | ||
broadcast: function broadcast(tag, data) { | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
broadcast: function (tag, data) { | ||
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
opts.from = addr; | ||
var _iterator = _createForOfIteratorHelper__default["default"](root.FCL_REGISTRY[addr].subs), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var to = _step.value; | ||
_send(to, tag, data, opts); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
for (let to of root.FCL_REGISTRY[addr].subs) send(to, tag, data, opts); | ||
}, | ||
subscribe: function subscribe(sub) { | ||
return sub != null && root.FCL_REGISTRY[addr].subs.add(sub); | ||
}, | ||
unsubscribe: function unsubscribe(sub) { | ||
return sub != null && root.FCL_REGISTRY[addr].subs["delete"](sub); | ||
}, | ||
subscriberCount: function subscriberCount() { | ||
return root.FCL_REGISTRY[addr].subs.size; | ||
}, | ||
hasSubs: function hasSubs() { | ||
return !!root.FCL_REGISTRY[addr].subs.size; | ||
}, | ||
put: function put(key, value) { | ||
subscribe: sub => sub != null && root.FCL_REGISTRY[addr].subs.add(sub), | ||
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) => { | ||
if (key != null) root.FCL_REGISTRY[addr].kvs[key] = value; | ||
}, | ||
get: function get(key, fallback) { | ||
var value = root.FCL_REGISTRY[addr].kvs[key]; | ||
get: (key, fallback) => { | ||
const value = root.FCL_REGISTRY[addr].kvs[key]; | ||
return value == null ? fallback : value; | ||
}, | ||
"delete": function _delete(key) { | ||
delete: key => { | ||
delete root.FCL_REGISTRY[addr].kvs[key]; | ||
}, | ||
update: function update(key, fn) { | ||
update: (key, fn) => { | ||
if (key != null) root.FCL_REGISTRY[addr].kvs[key] = fn(root.FCL_REGISTRY[addr].kvs[key]); | ||
}, | ||
keys: function keys() { | ||
keys: () => { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs); | ||
}, | ||
all: function all() { | ||
all: () => { | ||
return root.FCL_REGISTRY[addr].kvs; | ||
}, | ||
where: function where(pattern) { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce(function (acc, key) { | ||
return pattern.test(key) ? _objectSpread__default["default"](_objectSpread__default["default"]({}, acc), {}, _defineProperty__default["default"]({}, key, root.FCL_REGISTRY[addr].kvs[key])) : acc; | ||
where: pattern => { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce((acc, key) => { | ||
return pattern.test(key) ? { ...acc, | ||
[key]: root.FCL_REGISTRY[addr].kvs[key] | ||
} : acc; | ||
}, {}); | ||
}, | ||
merge: function merge() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(function (key) { | ||
return root.FCL_REGISTRY[addr].kvs[key] = data[key]; | ||
}); | ||
merge: function () { | ||
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(key => root.FCL_REGISTRY[addr].kvs[key] = data[key]); | ||
}, | ||
fatalError: function fatalError(error) { | ||
fatalError: error => { | ||
root.FCL_REGISTRY[addr].error = error; | ||
var _iterator2 = _createForOfIteratorHelper__default["default"](root.FCL_REGISTRY[addr].subs), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var to = _step2.value; | ||
_send(to, UPDATED); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
for (let to of root.FCL_REGISTRY[addr].subs) send(to, UPDATED); | ||
} | ||
}; | ||
if (_typeof__default["default"](fn) === "object") fn = fromHandlers(fn); | ||
queueMicrotask__default["default"]( /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"]().mark(function _callee2() { | ||
return _regeneratorRuntime__default["default"]().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return fn(ctx); | ||
case 2: | ||
kill(addr); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2); | ||
}))); | ||
if (typeof fn === "object") fn = fromHandlers(fn); | ||
queueMicrotask__default["default"](async () => { | ||
await fn(ctx); | ||
kill(addr); | ||
}); | ||
return addr; | ||
}; | ||
// Returns an unsubscribe function | ||
}; // Returns an unsubscribe function | ||
// A SUBSCRIBE handler will need to be created to handle the subscription event | ||
@@ -285,52 +192,29 @@ // | ||
// | ||
function subscriber(address, spawnFn, callback) { | ||
spawnFn(address); | ||
var EXIT = "@EXIT"; | ||
var self = spawn( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"]().mark(function _callee3(ctx) { | ||
var letter, error; | ||
return _regeneratorRuntime__default["default"]().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
ctx.send(address, SUBSCRIBE); | ||
case 1: | ||
_context3.next = 4; | ||
return ctx.receive(); | ||
case 4: | ||
letter = _context3.sent; | ||
error = root.FCL_REGISTRY[address].error; | ||
if (!(letter.tag === EXIT)) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 9: | ||
if (!error) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 13: | ||
callback(letter.data, null); | ||
_context3.next = 1; | ||
break; | ||
case 16: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
})); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
return function () { | ||
return _send(self, EXIT); | ||
}; | ||
} | ||
const EXIT = "@EXIT"; | ||
const self = spawn(async ctx => { | ||
ctx.send(address, SUBSCRIBE); | ||
// Returns a promise that returns a result | ||
while (1) { | ||
const letter = await ctx.receive(); | ||
const error = root.FCL_REGISTRY[address].error; | ||
if (letter.tag === EXIT) { | ||
ctx.send(address, UNSUBSCRIBE); | ||
return; | ||
} | ||
if (error) { | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return; | ||
} | ||
callback(letter.data, null); | ||
} | ||
}); | ||
return () => send(self, EXIT); | ||
} // Returns a promise that returns a result | ||
// A SNAPSHOT handler will need to be created to handle the snapshot event | ||
@@ -342,5 +226,6 @@ // | ||
// | ||
function snapshoter(address, spawnFn) { | ||
spawnFn(address); | ||
return _send(address, SNAPSHOT, null, { | ||
return send(address, SNAPSHOT, null, { | ||
expectReply: true, | ||
@@ -359,3 +244,3 @@ timeout: 0 | ||
exports.kill = kill; | ||
exports.send = _send; | ||
exports.send = send; | ||
exports.snapshoter = snapshoter; | ||
@@ -362,0 +247,0 @@ exports.spawn = spawn; |
@@ -1,33 +0,19 @@ | ||
import _defineProperty from '@babel/runtime/helpers/defineProperty'; | ||
import _objectSpread from '@babel/runtime/helpers/objectSpread2'; | ||
import _createForOfIteratorHelper from '@babel/runtime/helpers/createForOfIteratorHelper'; | ||
import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime'; | ||
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator'; | ||
import _typeof from '@babel/runtime/helpers/typeof'; | ||
import queueMicrotask from 'queue-microtask'; | ||
var mailbox = function mailbox() { | ||
var queue = []; | ||
const mailbox = () => { | ||
const queue = []; | ||
var next; | ||
return { | ||
deliver: function deliver(msg) { | ||
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
}))(); | ||
async deliver(msg) { | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
}, | ||
receive: function receive() { | ||
receive() { | ||
return new Promise(function innerReceive(resolve) { | ||
var msg = queue.shift(); | ||
const msg = queue.shift(); | ||
if (msg) return resolve(msg); | ||
@@ -37,35 +23,37 @@ next = resolve; | ||
} | ||
}; | ||
}; | ||
var INIT = "INIT"; | ||
var SUBSCRIBE = "SUBSCRIBE"; | ||
var UNSUBSCRIBE = "UNSUBSCRIBE"; | ||
var UPDATED = "UPDATED"; | ||
var SNAPSHOT = "SNAPSHOT"; | ||
var EXIT = "EXIT"; | ||
var TERMINATE = "TERMINATE"; | ||
var root = (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === "object" && global.global === global && global || (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" && window.window === window && window; | ||
const INIT = "INIT"; | ||
const SUBSCRIBE = "SUBSCRIBE"; | ||
const UNSUBSCRIBE = "UNSUBSCRIBE"; | ||
const UPDATED = "UPDATED"; | ||
const SNAPSHOT = "SNAPSHOT"; | ||
const EXIT = "EXIT"; | ||
const TERMINATE = "TERMINATE"; | ||
const root = typeof self === "object" && self.self === self && self || typeof global === "object" && global.global === global && global || typeof window === "object" && window.window === window && window; | ||
root.FCL_REGISTRY = root.FCL_REGISTRY == null ? {} : root.FCL_REGISTRY; | ||
var pid = 0; | ||
var DEFAULT_TIMEOUT = 5000; | ||
var _send = function send(addr, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise(function (reply, reject) { | ||
var expectReply = opts.expectReply || false; | ||
var timeout = opts.timeout != null ? opts.timeout : DEFAULT_TIMEOUT; | ||
var pid = 0b0; | ||
const DEFAULT_TIMEOUT = 5000; | ||
const send = function (addr, tag, data) { | ||
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise((reply, reject) => { | ||
const expectReply = opts.expectReply || false; | ||
const timeout = opts.timeout != null ? opts.timeout : DEFAULT_TIMEOUT; | ||
if (expectReply && timeout) { | ||
setTimeout(function () { | ||
return reject(new Error("Timeout: ".concat(timeout, "ms passed without a response."))); | ||
}, timeout); | ||
setTimeout(() => reject(new Error(`Timeout: ${timeout}ms passed without a response.`)), timeout); | ||
} | ||
var payload = { | ||
const payload = { | ||
to: addr, | ||
from: opts.from, | ||
tag: tag, | ||
data: data, | ||
timeout: timeout, | ||
reply: reply, | ||
reject: reject | ||
tag, | ||
data, | ||
timeout, | ||
reply, | ||
reject | ||
}; | ||
try { | ||
@@ -79,70 +67,39 @@ root.FCL_REGISTRY[addr] && root.FCL_REGISTRY[addr].mailbox.deliver(payload); | ||
}; | ||
var kill = function kill(addr) { | ||
const kill = addr => { | ||
delete root.FCL_REGISTRY[addr]; | ||
}; | ||
var fromHandlers = function fromHandlers() { | ||
var handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx) { | ||
var letter; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(typeof handlers[INIT] === "function")) { | ||
_context.next = 3; | ||
break; | ||
} | ||
_context.next = 3; | ||
return handlers[INIT](ctx); | ||
case 3: | ||
_context.next = 6; | ||
return ctx.receive(); | ||
case 6: | ||
letter = _context.sent; | ||
_context.prev = 7; | ||
if (!(letter.tag === EXIT)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
if (!(typeof handlers[TERMINATE] === "function")) { | ||
_context.next = 12; | ||
break; | ||
} | ||
_context.next = 12; | ||
return handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
case 12: | ||
return _context.abrupt("break", 25); | ||
case 13: | ||
_context.next = 15; | ||
return handlers[letter.tag](ctx, letter, letter.data || {}); | ||
case 15: | ||
_context.next = 20; | ||
break; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context["catch"](7); | ||
console.error("".concat(ctx.self(), " Error"), letter, _context.t0); | ||
case 20: | ||
_context.prev = 20; | ||
return _context.abrupt("continue", 3); | ||
case 23: | ||
_context.next = 3; | ||
break; | ||
case 25: | ||
case "end": | ||
return _context.stop(); | ||
const fromHandlers = function () { | ||
let handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return async ctx => { | ||
if (typeof handlers[INIT] === "function") await handlers[INIT](ctx); | ||
__loop: while (1) { | ||
const letter = await ctx.receive(); | ||
try { | ||
if (letter.tag === EXIT) { | ||
if (typeof handlers[TERMINATE] === "function") { | ||
await handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
} | ||
break __loop; | ||
} | ||
}, _callee, null, [[7, 17, 20, 23]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
await handlers[letter.tag](ctx, letter, letter.data || {}); | ||
} catch (error) { | ||
console.error(`${ctx.self()} Error`, letter, error); | ||
} finally { | ||
continue __loop; | ||
} | ||
} | ||
}; | ||
}; | ||
var spawn = function spawn(fn) { | ||
var addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
const spawn = function (fn) { | ||
let addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (addr == null) addr = ++pid; | ||
if (root.FCL_REGISTRY[addr] != null) return addr; | ||
root.FCL_REGISTRY[addr] = { | ||
addr: addr, | ||
addr, | ||
mailbox: mailbox(), | ||
@@ -153,110 +110,66 @@ subs: new Set(), | ||
}; | ||
var ctx = { | ||
self: function self() { | ||
return addr; | ||
}, | ||
receive: function receive() { | ||
return root.FCL_REGISTRY[addr].mailbox.receive(); | ||
}, | ||
send: function send(to, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
const ctx = { | ||
self: () => addr, | ||
receive: () => root.FCL_REGISTRY[addr].mailbox.receive(), | ||
send: function (to, tag, data) { | ||
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
opts.from = addr; | ||
return _send(to, tag, data, opts); | ||
return send(to, tag, data, opts); | ||
}, | ||
sendSelf: function sendSelf(tag, data, opts) { | ||
if (root.FCL_REGISTRY[addr]) _send(addr, tag, data, opts); | ||
sendSelf: (tag, data, opts) => { | ||
if (root.FCL_REGISTRY[addr]) send(addr, tag, data, opts); | ||
}, | ||
broadcast: function broadcast(tag, data) { | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
broadcast: function (tag, data) { | ||
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
opts.from = addr; | ||
var _iterator = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var to = _step.value; | ||
_send(to, tag, data, opts); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
for (let to of root.FCL_REGISTRY[addr].subs) send(to, tag, data, opts); | ||
}, | ||
subscribe: function subscribe(sub) { | ||
return sub != null && root.FCL_REGISTRY[addr].subs.add(sub); | ||
}, | ||
unsubscribe: function unsubscribe(sub) { | ||
return sub != null && root.FCL_REGISTRY[addr].subs["delete"](sub); | ||
}, | ||
subscriberCount: function subscriberCount() { | ||
return root.FCL_REGISTRY[addr].subs.size; | ||
}, | ||
hasSubs: function hasSubs() { | ||
return !!root.FCL_REGISTRY[addr].subs.size; | ||
}, | ||
put: function put(key, value) { | ||
subscribe: sub => sub != null && root.FCL_REGISTRY[addr].subs.add(sub), | ||
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) => { | ||
if (key != null) root.FCL_REGISTRY[addr].kvs[key] = value; | ||
}, | ||
get: function get(key, fallback) { | ||
var value = root.FCL_REGISTRY[addr].kvs[key]; | ||
get: (key, fallback) => { | ||
const value = root.FCL_REGISTRY[addr].kvs[key]; | ||
return value == null ? fallback : value; | ||
}, | ||
"delete": function _delete(key) { | ||
delete: key => { | ||
delete root.FCL_REGISTRY[addr].kvs[key]; | ||
}, | ||
update: function update(key, fn) { | ||
update: (key, fn) => { | ||
if (key != null) root.FCL_REGISTRY[addr].kvs[key] = fn(root.FCL_REGISTRY[addr].kvs[key]); | ||
}, | ||
keys: function keys() { | ||
keys: () => { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs); | ||
}, | ||
all: function all() { | ||
all: () => { | ||
return root.FCL_REGISTRY[addr].kvs; | ||
}, | ||
where: function where(pattern) { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce(function (acc, key) { | ||
return pattern.test(key) ? _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, root.FCL_REGISTRY[addr].kvs[key])) : acc; | ||
where: pattern => { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce((acc, key) => { | ||
return pattern.test(key) ? { ...acc, | ||
[key]: root.FCL_REGISTRY[addr].kvs[key] | ||
} : acc; | ||
}, {}); | ||
}, | ||
merge: function merge() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(function (key) { | ||
return root.FCL_REGISTRY[addr].kvs[key] = data[key]; | ||
}); | ||
merge: function () { | ||
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(key => root.FCL_REGISTRY[addr].kvs[key] = data[key]); | ||
}, | ||
fatalError: function fatalError(error) { | ||
fatalError: error => { | ||
root.FCL_REGISTRY[addr].error = error; | ||
var _iterator2 = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var to = _step2.value; | ||
_send(to, UPDATED); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
for (let to of root.FCL_REGISTRY[addr].subs) send(to, UPDATED); | ||
} | ||
}; | ||
if (_typeof(fn) === "object") fn = fromHandlers(fn); | ||
queueMicrotask( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return fn(ctx); | ||
case 2: | ||
kill(addr); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2); | ||
}))); | ||
if (typeof fn === "object") fn = fromHandlers(fn); | ||
queueMicrotask(async () => { | ||
await fn(ctx); | ||
kill(addr); | ||
}); | ||
return addr; | ||
}; | ||
// Returns an unsubscribe function | ||
}; // Returns an unsubscribe function | ||
// A SUBSCRIBE handler will need to be created to handle the subscription event | ||
@@ -269,52 +182,29 @@ // | ||
// | ||
function subscriber(address, spawnFn, callback) { | ||
spawnFn(address); | ||
var EXIT = "@EXIT"; | ||
var self = spawn( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(ctx) { | ||
var letter, error; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
ctx.send(address, SUBSCRIBE); | ||
case 1: | ||
_context3.next = 4; | ||
return ctx.receive(); | ||
case 4: | ||
letter = _context3.sent; | ||
error = root.FCL_REGISTRY[address].error; | ||
if (!(letter.tag === EXIT)) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 9: | ||
if (!error) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 13: | ||
callback(letter.data, null); | ||
_context3.next = 1; | ||
break; | ||
case 16: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
})); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
return function () { | ||
return _send(self, EXIT); | ||
}; | ||
} | ||
const EXIT = "@EXIT"; | ||
const self = spawn(async ctx => { | ||
ctx.send(address, SUBSCRIBE); | ||
// Returns a promise that returns a result | ||
while (1) { | ||
const letter = await ctx.receive(); | ||
const error = root.FCL_REGISTRY[address].error; | ||
if (letter.tag === EXIT) { | ||
ctx.send(address, UNSUBSCRIBE); | ||
return; | ||
} | ||
if (error) { | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return; | ||
} | ||
callback(letter.data, null); | ||
} | ||
}); | ||
return () => send(self, EXIT); | ||
} // Returns a promise that returns a result | ||
// A SNAPSHOT handler will need to be created to handle the snapshot event | ||
@@ -326,5 +216,6 @@ // | ||
// | ||
function snapshoter(address, spawnFn) { | ||
spawnFn(address); | ||
return _send(address, SNAPSHOT, null, { | ||
return send(address, SNAPSHOT, null, { | ||
expectReply: true, | ||
@@ -335,3 +226,3 @@ timeout: 0 | ||
export { EXIT, INIT, SNAPSHOT, SUBSCRIBE, TERMINATE, UNSUBSCRIBE, UPDATED, kill, _send as send, snapshoter, spawn, subscriber }; | ||
export { EXIT, INIT, SNAPSHOT, SUBSCRIBE, TERMINATE, UNSUBSCRIBE, UPDATED, kill, send, snapshoter, spawn, subscriber }; | ||
//# sourceMappingURL=actor.module.js.map |
@@ -7,491 +7,18 @@ (function (global, factory) { | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}, _typeof(obj); | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (_typeof(input) !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (_typeof(res) !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return _typeof(key) === "symbol" ? key : String(key); | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function F() {}; | ||
return { | ||
s: F, | ||
n: function n() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function e(_e) { | ||
throw _e; | ||
}, | ||
f: F | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
const mailbox = () => { | ||
const queue = []; | ||
var next; | ||
return { | ||
s: function s() { | ||
it = it.call(o); | ||
}, | ||
n: function n() { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function e(_e2) { | ||
didErr = true; | ||
err = _e2; | ||
}, | ||
f: function f() { | ||
try { | ||
if (!normalCompletion && it["return"] != null) it["return"](); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
async deliver(msg) { | ||
queue.push(msg); | ||
function _regeneratorRuntime() { | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
_regeneratorRuntime = function _regeneratorRuntime() { | ||
return exports; | ||
}; | ||
var exports = {}, | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
defineProperty = Object.defineProperty || function (obj, key, desc) { | ||
obj[key] = desc.value; | ||
}, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
return Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}), obj[key]; | ||
} | ||
try { | ||
define({}, ""); | ||
} catch (err) { | ||
define = function define(obj, key, value) { | ||
return obj[key] = value; | ||
}; | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
} | ||
} | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
define(IteratorPrototype, iteratorSymbol, function () { | ||
return this; | ||
}); | ||
var getProto = Object.getPrototypeOf, | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
define(prototype, method, function (arg) { | ||
return this._invoke(method, arg); | ||
}); | ||
}); | ||
} | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if ("throw" !== record.type) { | ||
var result = record.arg, | ||
value = result.value; | ||
return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}) : PromiseImpl.resolve(value).then(function (unwrapped) { | ||
result.value = unwrapped, resolve(result); | ||
}, function (error) { | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
defineProperty(this, "_invoke", { | ||
value: function value(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} | ||
}); | ||
} | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
} | ||
function maybeInvokeDelegate(delegate, context) { | ||
var methodName = context.method, | ||
method = delegate.iterator[methodName]; | ||
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
var info = record.arg; | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
} | ||
function pushTryEntry(locs) { | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal", delete record.arg, entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); | ||
} | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) return iteratorMethod.call(iterable); | ||
if ("function" == typeof iterable.next) return iterable; | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
function doneResult() { | ||
return { | ||
value: undefined, | ||
done: !0 | ||
}; | ||
} | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { | ||
value: GeneratorFunctionPrototype, | ||
configurable: !0 | ||
}), defineProperty(GeneratorFunctionPrototype, "constructor", { | ||
value: GeneratorFunction, | ||
configurable: !0 | ||
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
}, exports.mark = function (genFun) { | ||
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; | ||
}, exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
void 0 === PromiseImpl && (PromiseImpl = Promise); | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { | ||
return this; | ||
}), define(Gp, "toString", function () { | ||
return "[object Generator]"; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
for (; keys.length;) { | ||
var key = keys.pop(); | ||
if (key in object) return next.value = key, next.done = !1, next; | ||
} | ||
return next.done = !0, next; | ||
}; | ||
}, exports.values = values, Context.prototype = { | ||
constructor: Context, | ||
reset: function reset(skipTempReset) { | ||
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); | ||
}, | ||
stop: function stop() { | ||
this.done = !0; | ||
var rootRecord = this.tryEntries[0].completion; | ||
if ("throw" === rootRecord.type) throw rootRecord.arg; | ||
return this.rval; | ||
}, | ||
dispatchException: function dispatchException(exception) { | ||
if (this.done) throw exception; | ||
var context = this; | ||
function handle(loc, caught) { | ||
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i], | ||
record = entry.completion; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
} else { | ||
if (!hasFinally) throw new Error("try statement without catch or finally"); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function abrupt(type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); | ||
}, | ||
complete: function complete(record, afterLoc) { | ||
if ("throw" === record.type) throw record.arg; | ||
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
}, | ||
finish: function finish(finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; | ||
} | ||
}, | ||
"catch": function _catch(tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if ("throw" === record.type) { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
return thrown; | ||
} | ||
} | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function delegateYield(iterable, resultName, nextLoc) { | ||
return this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}, "next" === this.method && (this.arg = undefined), ContinueSentinel; | ||
} | ||
}, exports; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
var mailbox = function mailbox() { | ||
var queue = []; | ||
var next; | ||
return { | ||
deliver: function deliver(msg) { | ||
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
}))(); | ||
}, | ||
receive: function receive() { | ||
receive() { | ||
return new Promise(function innerReceive(resolve) { | ||
var msg = queue.shift(); | ||
const msg = queue.shift(); | ||
if (msg) return resolve(msg); | ||
@@ -501,2 +28,3 @@ next = resolve; | ||
} | ||
}; | ||
@@ -508,43 +36,39 @@ }; | ||
/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */ | ||
var promise; | ||
var queueMicrotask_1 = typeof queueMicrotask === 'function' ? queueMicrotask.bind(typeof window !== 'undefined' ? window : commonjsGlobal) | ||
// reuse resolved promise, and allocate it lazily | ||
: function (cb) { | ||
return (promise || (promise = Promise.resolve())).then(cb)["catch"](function (err) { | ||
return setTimeout(function () { | ||
throw err; | ||
}, 0); | ||
}); | ||
}; | ||
let promise; | ||
var queueMicrotask_1 = typeof queueMicrotask === 'function' ? queueMicrotask.bind(typeof window !== 'undefined' ? window : commonjsGlobal) // reuse resolved promise, and allocate it lazily | ||
: cb => (promise || (promise = Promise.resolve())).then(cb).catch(err => setTimeout(() => { | ||
throw err; | ||
}, 0)); | ||
var INIT = "INIT"; | ||
var SUBSCRIBE = "SUBSCRIBE"; | ||
var UNSUBSCRIBE = "UNSUBSCRIBE"; | ||
var UPDATED = "UPDATED"; | ||
var SNAPSHOT = "SNAPSHOT"; | ||
var EXIT = "EXIT"; | ||
var TERMINATE = "TERMINATE"; | ||
var root = (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === "object" && global.global === global && global || (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" && window.window === window && window; | ||
const INIT = "INIT"; | ||
const SUBSCRIBE = "SUBSCRIBE"; | ||
const UNSUBSCRIBE = "UNSUBSCRIBE"; | ||
const UPDATED = "UPDATED"; | ||
const SNAPSHOT = "SNAPSHOT"; | ||
const EXIT = "EXIT"; | ||
const TERMINATE = "TERMINATE"; | ||
const root = typeof self === "object" && self.self === self && self || typeof global === "object" && global.global === global && global || typeof window === "object" && window.window === window && window; | ||
root.FCL_REGISTRY = root.FCL_REGISTRY == null ? {} : root.FCL_REGISTRY; | ||
var pid = 0; | ||
var DEFAULT_TIMEOUT = 5000; | ||
var _send = function send(addr, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise(function (reply, reject) { | ||
var expectReply = opts.expectReply || false; | ||
var timeout = opts.timeout != null ? opts.timeout : DEFAULT_TIMEOUT; | ||
var pid = 0b0; | ||
const DEFAULT_TIMEOUT = 5000; | ||
const send = function (addr, tag, data) { | ||
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise((reply, reject) => { | ||
const expectReply = opts.expectReply || false; | ||
const timeout = opts.timeout != null ? opts.timeout : DEFAULT_TIMEOUT; | ||
if (expectReply && timeout) { | ||
setTimeout(function () { | ||
return reject(new Error("Timeout: ".concat(timeout, "ms passed without a response."))); | ||
}, timeout); | ||
setTimeout(() => reject(new Error(`Timeout: ${timeout}ms passed without a response.`)), timeout); | ||
} | ||
var payload = { | ||
const payload = { | ||
to: addr, | ||
from: opts.from, | ||
tag: tag, | ||
data: data, | ||
timeout: timeout, | ||
reply: reply, | ||
reject: reject | ||
tag, | ||
data, | ||
timeout, | ||
reply, | ||
reject | ||
}; | ||
try { | ||
@@ -558,70 +82,39 @@ root.FCL_REGISTRY[addr] && root.FCL_REGISTRY[addr].mailbox.deliver(payload); | ||
}; | ||
var kill = function kill(addr) { | ||
const kill = addr => { | ||
delete root.FCL_REGISTRY[addr]; | ||
}; | ||
var fromHandlers = function fromHandlers() { | ||
var handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx) { | ||
var letter; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(typeof handlers[INIT] === "function")) { | ||
_context.next = 3; | ||
break; | ||
} | ||
_context.next = 3; | ||
return handlers[INIT](ctx); | ||
case 3: | ||
_context.next = 6; | ||
return ctx.receive(); | ||
case 6: | ||
letter = _context.sent; | ||
_context.prev = 7; | ||
if (!(letter.tag === EXIT)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
if (!(typeof handlers[TERMINATE] === "function")) { | ||
_context.next = 12; | ||
break; | ||
} | ||
_context.next = 12; | ||
return handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
case 12: | ||
return _context.abrupt("break", 25); | ||
case 13: | ||
_context.next = 15; | ||
return handlers[letter.tag](ctx, letter, letter.data || {}); | ||
case 15: | ||
_context.next = 20; | ||
break; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context["catch"](7); | ||
console.error("".concat(ctx.self(), " Error"), letter, _context.t0); | ||
case 20: | ||
_context.prev = 20; | ||
return _context.abrupt("continue", 3); | ||
case 23: | ||
_context.next = 3; | ||
break; | ||
case 25: | ||
case "end": | ||
return _context.stop(); | ||
const fromHandlers = function () { | ||
let handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return async ctx => { | ||
if (typeof handlers[INIT] === "function") await handlers[INIT](ctx); | ||
__loop: while (1) { | ||
const letter = await ctx.receive(); | ||
try { | ||
if (letter.tag === EXIT) { | ||
if (typeof handlers[TERMINATE] === "function") { | ||
await handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
} | ||
break __loop; | ||
} | ||
}, _callee, null, [[7, 17, 20, 23]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
await handlers[letter.tag](ctx, letter, letter.data || {}); | ||
} catch (error) { | ||
console.error(`${ctx.self()} Error`, letter, error); | ||
} finally { | ||
continue __loop; | ||
} | ||
} | ||
}; | ||
}; | ||
var spawn = function spawn(fn) { | ||
var addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
const spawn = function (fn) { | ||
let addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (addr == null) addr = ++pid; | ||
if (root.FCL_REGISTRY[addr] != null) return addr; | ||
root.FCL_REGISTRY[addr] = { | ||
addr: addr, | ||
addr, | ||
mailbox: mailbox(), | ||
@@ -632,110 +125,66 @@ subs: new Set(), | ||
}; | ||
var ctx = { | ||
self: function self() { | ||
return addr; | ||
}, | ||
receive: function receive() { | ||
return root.FCL_REGISTRY[addr].mailbox.receive(); | ||
}, | ||
send: function send(to, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
const ctx = { | ||
self: () => addr, | ||
receive: () => root.FCL_REGISTRY[addr].mailbox.receive(), | ||
send: function (to, tag, data) { | ||
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
opts.from = addr; | ||
return _send(to, tag, data, opts); | ||
return send(to, tag, data, opts); | ||
}, | ||
sendSelf: function sendSelf(tag, data, opts) { | ||
if (root.FCL_REGISTRY[addr]) _send(addr, tag, data, opts); | ||
sendSelf: (tag, data, opts) => { | ||
if (root.FCL_REGISTRY[addr]) send(addr, tag, data, opts); | ||
}, | ||
broadcast: function broadcast(tag, data) { | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
broadcast: function (tag, data) { | ||
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
opts.from = addr; | ||
var _iterator = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var to = _step.value; | ||
_send(to, tag, data, opts); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
for (let to of root.FCL_REGISTRY[addr].subs) send(to, tag, data, opts); | ||
}, | ||
subscribe: function subscribe(sub) { | ||
return sub != null && root.FCL_REGISTRY[addr].subs.add(sub); | ||
}, | ||
unsubscribe: function unsubscribe(sub) { | ||
return sub != null && root.FCL_REGISTRY[addr].subs["delete"](sub); | ||
}, | ||
subscriberCount: function subscriberCount() { | ||
return root.FCL_REGISTRY[addr].subs.size; | ||
}, | ||
hasSubs: function hasSubs() { | ||
return !!root.FCL_REGISTRY[addr].subs.size; | ||
}, | ||
put: function put(key, value) { | ||
subscribe: sub => sub != null && root.FCL_REGISTRY[addr].subs.add(sub), | ||
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) => { | ||
if (key != null) root.FCL_REGISTRY[addr].kvs[key] = value; | ||
}, | ||
get: function get(key, fallback) { | ||
var value = root.FCL_REGISTRY[addr].kvs[key]; | ||
get: (key, fallback) => { | ||
const value = root.FCL_REGISTRY[addr].kvs[key]; | ||
return value == null ? fallback : value; | ||
}, | ||
"delete": function _delete(key) { | ||
delete: key => { | ||
delete root.FCL_REGISTRY[addr].kvs[key]; | ||
}, | ||
update: function update(key, fn) { | ||
update: (key, fn) => { | ||
if (key != null) root.FCL_REGISTRY[addr].kvs[key] = fn(root.FCL_REGISTRY[addr].kvs[key]); | ||
}, | ||
keys: function keys() { | ||
keys: () => { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs); | ||
}, | ||
all: function all() { | ||
all: () => { | ||
return root.FCL_REGISTRY[addr].kvs; | ||
}, | ||
where: function where(pattern) { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce(function (acc, key) { | ||
return pattern.test(key) ? _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, root.FCL_REGISTRY[addr].kvs[key])) : acc; | ||
where: pattern => { | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce((acc, key) => { | ||
return pattern.test(key) ? { ...acc, | ||
[key]: root.FCL_REGISTRY[addr].kvs[key] | ||
} : acc; | ||
}, {}); | ||
}, | ||
merge: function merge() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(function (key) { | ||
return root.FCL_REGISTRY[addr].kvs[key] = data[key]; | ||
}); | ||
merge: function () { | ||
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(key => root.FCL_REGISTRY[addr].kvs[key] = data[key]); | ||
}, | ||
fatalError: function fatalError(error) { | ||
fatalError: error => { | ||
root.FCL_REGISTRY[addr].error = error; | ||
var _iterator2 = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var to = _step2.value; | ||
_send(to, UPDATED); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
for (let to of root.FCL_REGISTRY[addr].subs) send(to, UPDATED); | ||
} | ||
}; | ||
if (_typeof(fn) === "object") fn = fromHandlers(fn); | ||
queueMicrotask_1( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return fn(ctx); | ||
case 2: | ||
kill(addr); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2); | ||
}))); | ||
if (typeof fn === "object") fn = fromHandlers(fn); | ||
queueMicrotask_1(async () => { | ||
await fn(ctx); | ||
kill(addr); | ||
}); | ||
return addr; | ||
}; | ||
// Returns an unsubscribe function | ||
}; // Returns an unsubscribe function | ||
// A SUBSCRIBE handler will need to be created to handle the subscription event | ||
@@ -748,52 +197,29 @@ // | ||
// | ||
function subscriber(address, spawnFn, callback) { | ||
spawnFn(address); | ||
var EXIT = "@EXIT"; | ||
var self = spawn( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(ctx) { | ||
var letter, error; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
ctx.send(address, SUBSCRIBE); | ||
case 1: | ||
_context3.next = 4; | ||
return ctx.receive(); | ||
case 4: | ||
letter = _context3.sent; | ||
error = root.FCL_REGISTRY[address].error; | ||
if (!(letter.tag === EXIT)) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 9: | ||
if (!error) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 13: | ||
callback(letter.data, null); | ||
_context3.next = 1; | ||
break; | ||
case 16: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
})); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
return function () { | ||
return _send(self, EXIT); | ||
}; | ||
} | ||
const EXIT = "@EXIT"; | ||
const self = spawn(async ctx => { | ||
ctx.send(address, SUBSCRIBE); | ||
// Returns a promise that returns a result | ||
while (1) { | ||
const letter = await ctx.receive(); | ||
const error = root.FCL_REGISTRY[address].error; | ||
if (letter.tag === EXIT) { | ||
ctx.send(address, UNSUBSCRIBE); | ||
return; | ||
} | ||
if (error) { | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return; | ||
} | ||
callback(letter.data, null); | ||
} | ||
}); | ||
return () => send(self, EXIT); | ||
} // Returns a promise that returns a result | ||
// A SNAPSHOT handler will need to be created to handle the snapshot event | ||
@@ -805,5 +231,6 @@ // | ||
// | ||
function snapshoter(address, spawnFn) { | ||
spawnFn(address); | ||
return _send(address, SNAPSHOT, null, { | ||
return send(address, SNAPSHOT, null, { | ||
expectReply: true, | ||
@@ -822,3 +249,3 @@ timeout: 0 | ||
exports.kill = kill; | ||
exports.send = _send; | ||
exports.send = send; | ||
exports.snapshoter = snapshoter; | ||
@@ -825,0 +252,0 @@ exports.spawn = spawn; |
{ | ||
"name": "@onflow/util-actor", | ||
"version": "1.2.0-alpha.2", | ||
"version": "1.2.0-alpha.3", | ||
"description": "A mechanism for forcing order/transitions of scoped async state", | ||
@@ -15,11 +15,5 @@ "license": "Apache-2.0", | ||
}, | ||
"jest": { | ||
"transform": { | ||
".js": "jest-esm-transformer" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@onflow/fcl-bundle": "^1.3.0-alpha.0", | ||
"jest": "^27.5.1", | ||
"jest-esm-transformer": "1.0.0" | ||
"jest": "^29.5.0" | ||
}, | ||
@@ -26,0 +20,0 @@ "dependencies": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
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
2
75138
11
636
1