@quenk/potoo 4.0.3 → 4.0.5
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.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Err } from '@quenk/noni/lib/control/error';
|
|
2
|
-
import { Future } from '@quenk/noni/lib/control/monad/future';
|
|
3
2
|
import { Runtime } from '../system/vm/runtime';
|
|
4
3
|
import { Address } from '../address';
|
|
5
4
|
import { Spawnable } from '../template';
|
|
@@ -27,27 +26,27 @@ export declare abstract class AbstractResident implements Resident {
|
|
|
27
26
|
start(): Promise<void>;
|
|
28
27
|
run(): Promise<void>;
|
|
29
28
|
stop(): Promise<void>;
|
|
30
|
-
|
|
29
|
+
receive<T>(cases?: TypeCase<T>[]): Promise<T>;
|
|
31
30
|
watch<T>(task: () => Promise<T>): Promise<void>;
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
|
-
*
|
|
35
|
-
* a message. The same receiver is applied to each and every message.
|
|
33
|
+
* Mutable actors can change their behaviour after message processing.
|
|
36
34
|
*/
|
|
37
|
-
export declare abstract class
|
|
38
|
-
/**
|
|
39
|
-
* match provides the list of Case classes that the actor will be used
|
|
40
|
-
* to process incoming messages.
|
|
41
|
-
*/
|
|
42
|
-
match(): TypeCase<T>[];
|
|
43
|
-
start(): Promise<void>;
|
|
35
|
+
export declare abstract class Mutable extends AbstractResident {
|
|
44
36
|
}
|
|
45
37
|
/**
|
|
46
|
-
*
|
|
38
|
+
* Immutable is an actor whose behaviour does not change when a message is
|
|
39
|
+
* received.
|
|
40
|
+
*
|
|
41
|
+
* For each message received, the same set of TypeCase classes are applied.
|
|
42
|
+
* This class is useful for simple request/response style actors that do
|
|
43
|
+
* not require much complicated logic.
|
|
47
44
|
*/
|
|
48
|
-
export declare abstract class
|
|
45
|
+
export declare abstract class Immutable<T> extends AbstractResident {
|
|
49
46
|
/**
|
|
50
|
-
*
|
|
47
|
+
* selectors provides the list of TypeCase classes that will be applied to
|
|
48
|
+
* all incoming messages.
|
|
51
49
|
*/
|
|
52
|
-
|
|
50
|
+
selectors(): TypeCase<T>[];
|
|
51
|
+
start(): Promise<void>;
|
|
53
52
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const future_1 = require("@quenk/noni/lib/control/monad/future");
|
|
3
|
+
exports.Immutable = exports.Mutable = exports.AbstractResident = void 0;
|
|
5
4
|
/**
|
|
6
5
|
* AbstractResident is a base implementation of a Resident actor.
|
|
7
6
|
*/
|
|
@@ -33,40 +32,41 @@ class AbstractResident {
|
|
|
33
32
|
}
|
|
34
33
|
async run() { }
|
|
35
34
|
async stop() { }
|
|
35
|
+
async receive(cases = []) {
|
|
36
|
+
return this.runtime.receive(cases);
|
|
37
|
+
}
|
|
36
38
|
watch(task) {
|
|
37
39
|
return this.runtime.watch(task);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
exports.AbstractResident = AbstractResident;
|
|
41
43
|
/**
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
+
* Mutable actors can change their behaviour after message processing.
|
|
45
|
+
*/
|
|
46
|
+
class Mutable extends AbstractResident {
|
|
47
|
+
}
|
|
48
|
+
exports.Mutable = Mutable;
|
|
49
|
+
/**
|
|
50
|
+
* Immutable is an actor whose behaviour does not change when a message is
|
|
51
|
+
* received.
|
|
52
|
+
*
|
|
53
|
+
* For each message received, the same set of TypeCase classes are applied.
|
|
54
|
+
* This class is useful for simple request/response style actors that do
|
|
55
|
+
* not require much complicated logic.
|
|
44
56
|
*/
|
|
45
57
|
class Immutable extends AbstractResident {
|
|
46
58
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
59
|
+
* selectors provides the list of TypeCase classes that will be applied to
|
|
60
|
+
* all incoming messages.
|
|
49
61
|
*/
|
|
50
|
-
|
|
62
|
+
selectors() {
|
|
51
63
|
return [];
|
|
52
64
|
}
|
|
53
65
|
async start() {
|
|
54
66
|
await this.run();
|
|
55
67
|
while (this.runtime.isValid())
|
|
56
|
-
await this.
|
|
68
|
+
await this.receive(this.selectors());
|
|
57
69
|
}
|
|
58
70
|
}
|
|
59
71
|
exports.Immutable = Immutable;
|
|
60
|
-
/**
|
|
61
|
-
* Mutable actors can change their behaviour after message processing.
|
|
62
|
-
*/
|
|
63
|
-
class Mutable extends AbstractResident {
|
|
64
|
-
/**
|
|
65
|
-
* receive a message from the actor's mailbox.
|
|
66
|
-
*/
|
|
67
|
-
receive(cases = []) {
|
|
68
|
-
return future_1.Future.do(async () => this.runtime.receive(cases));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.Mutable = Mutable;
|
|
72
72
|
//# sourceMappingURL=resident.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resident.js","sourceRoot":"","sources":["resident.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"resident.js","sourceRoot":"","sources":["resident.ts"],"names":[],"mappings":";;;AAcA;;GAEG;AACH,MAAsB,gBAAgB;IAClC,YAAmB,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;QAEnC,SAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAFa,CAAC;IAIvC,KAAK,CAAC,MAAM,CAAC,GAAY;QACrB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,MAAiB;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,IAAI,CAAI,IAAa,EAAE,GAAM;QAC/B,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAQ;QAChB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAa;QACpB,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,IAAI;QACN,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,GAAG,KAAI,CAAC;IAEd,KAAK,CAAC,IAAI,KAAI,CAAC;IAEf,KAAK,CAAC,OAAO,CAAI,QAAqB,EAAE;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAI,IAAsB;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACJ;AA5CD,4CA4CC;AAED;;GAEG;AACH,MAAsB,OAAQ,SAAQ,gBAAgB;CAAG;AAAzD,0BAAyD;AAEzD;;;;;;;GAOG;AACH,MAAsB,SAAa,SAAQ,gBAAgB;IACvD;;;OAGG;IACH,SAAS;QACL,OAAO,EAAE,CAAC;IACd,CAAC;IAED,KAAK,CAAC,KAAK;QACP,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YAAE,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,CAAC;CACJ;AAbD,8BAaC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Err } from '@quenk/noni/lib/control/error';
|
|
2
|
-
import { Future } from '@quenk/noni/lib/control/monad/future';
|
|
3
2
|
|
|
4
3
|
import { Runtime } from '../system/vm/runtime';
|
|
5
4
|
import { Address } from '../address';
|
|
@@ -53,7 +52,9 @@ export abstract class AbstractResident implements Resident {
|
|
|
53
52
|
|
|
54
53
|
async stop() {}
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
async receive<T>(cases: TypeCase<T>[]=[]) {
|
|
56
|
+
return this.runtime.receive(cases);
|
|
57
|
+
}
|
|
57
58
|
|
|
58
59
|
watch<T>(task: () => Promise<T>) {
|
|
59
60
|
return this.runtime.watch(task);
|
|
@@ -61,32 +62,29 @@ export abstract class AbstractResident implements Resident {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
|
-
*
|
|
65
|
-
|
|
65
|
+
* Mutable actors can change their behaviour after message processing.
|
|
66
|
+
*/
|
|
67
|
+
export abstract class Mutable extends AbstractResident {}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Immutable is an actor whose behaviour does not change when a message is
|
|
71
|
+
* received.
|
|
72
|
+
*
|
|
73
|
+
* For each message received, the same set of TypeCase classes are applied.
|
|
74
|
+
* This class is useful for simple request/response style actors that do
|
|
75
|
+
* not require much complicated logic.
|
|
66
76
|
*/
|
|
67
77
|
export abstract class Immutable<T> extends AbstractResident {
|
|
68
78
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
79
|
+
* selectors provides the list of TypeCase classes that will be applied to
|
|
80
|
+
* all incoming messages.
|
|
71
81
|
*/
|
|
72
|
-
|
|
82
|
+
selectors(): TypeCase<T>[] {
|
|
73
83
|
return [];
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
async start() {
|
|
77
87
|
await this.run();
|
|
78
|
-
while (this.runtime.isValid()) await this.
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Mutable actors can change their behaviour after message processing.
|
|
84
|
-
*/
|
|
85
|
-
export abstract class Mutable extends AbstractResident {
|
|
86
|
-
/**
|
|
87
|
-
* receive a message from the actor's mailbox.
|
|
88
|
-
*/
|
|
89
|
-
receive<T>(cases: TypeCase<T>[] = []): Future<T> {
|
|
90
|
-
return Future.do(async () => this.runtime.receive(cases));
|
|
88
|
+
while (this.runtime.isValid()) await this.receive(this.selectors());
|
|
91
89
|
}
|
|
92
90
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenk/potoo",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Message passing virtual machine.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
"eslint-plugin-prettier": "^4.2.1",
|
|
24
24
|
"jest": "^29.7.0",
|
|
25
25
|
"jest-mock-extended": "^3.0.7",
|
|
26
|
-
"prettier": "^
|
|
26
|
+
"prettier": "^2.8.4",
|
|
27
27
|
"ts-jest": "^29.1.2",
|
|
28
|
+
"ts-node": "^10.9.2",
|
|
28
29
|
"typescript": "^5.5.4"
|
|
29
30
|
},
|
|
30
31
|
"author": "Quenk Technologies Limited",
|