@stevvvns/act 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/t +0 -87
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stevvvns/act",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "main": "index.js",
6
6
  "directories": {
7
7
  "test": "test"
package/src/t DELETED
@@ -1,87 +0,0 @@
1
- # remote
2
- return (...args) => {
3
- const id = randomUUID();
4
- const pr = new Promise((resolve, reject) => {
5
- if (shuttingDown) {
6
- return;
7
- }
8
- if (Object.keys(dispatch[name]).length >= maxMb[name]) {
9
- log({ evt: 'full mailbox', name, max: maxMb[name] });
10
- return reject('mailbox full');
11
- }
12
- dispatch[name][id] = { resolve, reject };
13
- log({ evt: 'outgoing', remote: true, name, id, mtd, args });
14
- try {
15
- ##
16
- procs[name].send(['call', [id, name, mtd, args]]);
17
- ##
18
- }
19
- catch (ex) {
20
- reject(ex);
21
- }
22
- });
23
- const reaper = () => {
24
- if (dispatch[name][id]) {
25
- dispatch[name][id].reject('actor timed out');
26
- }
27
- };
28
- timeouts[id] = setTimeout(reaper, timeout);
29
- pr.timeout = num => {
30
- clearTimeout(timeouts[id]);
31
- const asMs = typeof num === 'string' ? toMs(num) : num;
32
- timeouts[id] = setTimeout(reaper, asMs);
33
- return pr;
34
- };
35
- return pr;
36
- };
37
-
38
- # fork
39
- return (...args) => {
40
- const id = randomUUID();
41
- const pr = new Promise((resolve, reject) => {
42
- if (shuttingDown) {
43
- return;
44
- }
45
- if (Object.keys(dispatch[name]).length >= maxMb[name]) {
46
- log({ evt: 'full mailbox', name, max: maxMb[name] });
47
- return reject('mailbox full');
48
- }
49
- ### fork only
50
- if (!procs[name].connected) {
51
- for (const [id, { reject }] of Object.entries(dispatch[name])) {
52
- if (timeouts[id]) {
53
- clearTimeout(timeouts.id);
54
- }
55
- reject('disconnected');
56
- }
57
- dispatch[name] = {};
58
- procs[name] = fork(settings.module);
59
- procs[name].on('message', msg => handleResponse(name, decode(msg)));
60
- return reject('disconnected');
61
- }
62
- ###
63
- dispatch[name][id] = { resolve, reject };
64
- log({ evt: 'outgoing', name, id, mtd, args });
65
- try {
66
- ##
67
- procs[name].send(Object.values(encode([id, mtd, args])));
68
- ##
69
- }
70
- catch (ex) {
71
- reject(ex);
72
- }
73
- });
74
- const reaper = () => {
75
- if (dispatch[name][id]) {
76
- dispatch[name][id].reject('actor timed out');
77
- }
78
- };
79
- timeouts[id] = setTimeout(reaper, timeout);
80
- pr.timeout = num => {
81
- clearTimeout(timeouts[id]);
82
- const asMs = typeof num === 'string' ? toMs(num) : num;
83
- timeouts[id] = setTimeout(reaper, asMs);
84
- return pr;
85
- };
86
- return pr;
87
- };