@quenk/potoo 4.0.7 → 4.0.11
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.
- package/lib/actor/address.js.map +1 -1
- package/lib/actor/api.d.ts +2 -2
- package/lib/actor/api.js.map +1 -1
- package/lib/actor/framework/index.js +2 -2
- package/lib/actor/framework/index.js.map +1 -1
- package/lib/actor/framework/process.d.ts +3 -2
- package/lib/actor/framework/process.js.map +1 -1
- package/lib/actor/framework/resident.d.ts +5 -3
- package/lib/actor/framework/resident.js +2 -0
- package/lib/actor/framework/resident.js.map +1 -1
- package/lib/actor/index.js.map +1 -1
- package/lib/actor/system/vm/allocator/index.js.map +1 -1
- package/lib/actor/system/vm/allocator/map.js +7 -4
- package/lib/actor/system/vm/allocator/map.js.map +1 -1
- package/lib/actor/system/vm/conf.js.map +1 -1
- package/lib/actor/system/vm/event/dispatcher.d.ts +31 -12
- package/lib/actor/system/vm/event/dispatcher.js +72 -20
- package/lib/actor/system/vm/event/dispatcher.js.map +1 -1
- package/lib/actor/system/vm/event/index.js.map +1 -1
- package/lib/actor/system/vm/frame.js.map +1 -1
- package/lib/actor/system/vm/group.js.map +1 -1
- package/lib/actor/system/vm/index.js +2 -2
- package/lib/actor/system/vm/index.js.map +1 -1
- package/lib/actor/system/vm/log/index.js.map +1 -1
- package/lib/actor/system/vm/log/writer.js.map +1 -1
- package/lib/actor/system/vm/object/foreign.js.map +1 -1
- package/lib/actor/system/vm/object/index.js.map +1 -1
- package/lib/actor/system/vm/object/list.js.map +1 -1
- package/lib/actor/system/vm/op/actor.js.map +1 -1
- package/lib/actor/system/vm/op/base.js.map +1 -1
- package/lib/actor/system/vm/op/index.js.map +1 -1
- package/lib/actor/system/vm/op/object.js.map +1 -1
- package/lib/actor/system/vm/registry.js.map +1 -1
- package/lib/actor/system/vm/runtime/error.js.map +1 -1
- package/lib/actor/system/vm/runtime.js.map +1 -1
- package/lib/actor/system/vm/scheduler.js.map +1 -1
- package/lib/actor/system/vm/script/index.js.map +1 -1
- package/lib/actor/system/vm/script/info.js.map +1 -1
- package/lib/actor/system/vm/strategy/error.js.map +1 -1
- package/lib/actor/system/vm/thread/factory.js.map +1 -1
- package/lib/actor/system/vm/thread/index.js.map +1 -1
- package/lib/actor/system/vm/thread/process.js.map +1 -1
- package/lib/actor/system/vm/thread/shared/index.js.map +1 -1
- package/lib/actor/system/vm/thread/shared/js.d.ts +2 -2
- package/lib/actor/system/vm/thread/shared/js.js +3 -3
- package/lib/actor/system/vm/thread/shared/js.js.map +1 -1
- package/lib/actor/system/vm/type.js.map +1 -1
- package/lib/actor/template.d.ts +20 -0
- package/lib/actor/template.js +17 -1
- package/lib/actor/template.js.map +1 -1
- package/package.json +11 -9
- package/lib/actor/address.ts +0 -90
- package/lib/actor/api.ts +0 -57
- package/lib/actor/framework/index.ts +0 -1
- package/lib/actor/framework/process.ts +0 -87
- package/lib/actor/framework/resident.ts +0 -90
- package/lib/actor/index.ts +0 -35
- package/lib/actor/system/vm/allocator/index.ts +0 -43
- package/lib/actor/system/vm/allocator/map.ts +0 -256
- package/lib/actor/system/vm/conf.ts +0 -33
- package/lib/actor/system/vm/event/dispatcher.ts +0 -85
- package/lib/actor/system/vm/event/index.ts +0 -143
- package/lib/actor/system/vm/frame.ts +0 -484
- package/lib/actor/system/vm/group.ts +0 -46
- package/lib/actor/system/vm/index.ts +0 -230
- package/lib/actor/system/vm/log/index.ts +0 -73
- package/lib/actor/system/vm/log/writer.ts +0 -96
- package/lib/actor/system/vm/object/foreign.ts +0 -10
- package/lib/actor/system/vm/object/index.ts +0 -4
- package/lib/actor/system/vm/object/list.ts +0 -8
- package/lib/actor/system/vm/op/actor.ts +0 -126
- package/lib/actor/system/vm/op/base.ts +0 -243
- package/lib/actor/system/vm/op/index.ts +0 -388
- package/lib/actor/system/vm/op/object.ts +0 -81
- package/lib/actor/system/vm/registry.ts +0 -223
- package/lib/actor/system/vm/runtime/error.ts +0 -248
- package/lib/actor/system/vm/runtime.ts +0 -31
- package/lib/actor/system/vm/scheduler.ts +0 -108
- package/lib/actor/system/vm/script/index.ts +0 -64
- package/lib/actor/system/vm/script/info.ts +0 -359
- package/lib/actor/system/vm/strategy/error.ts +0 -88
- package/lib/actor/system/vm/thread/factory.ts +0 -29
- package/lib/actor/system/vm/thread/index.ts +0 -29
- package/lib/actor/system/vm/thread/process.ts +0 -134
- package/lib/actor/system/vm/thread/shared/index.ts +0 -50
- package/lib/actor/system/vm/thread/shared/js.ts +0 -151
- package/lib/actor/system/vm/type.ts +0 -115
- package/lib/actor/template.ts +0 -170
- package/lib/tsconfig.json +0 -22
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Err } from '@quenk/noni/lib/control/error';
|
|
2
|
-
import { Future } from '@quenk/noni/lib/control/monad/future';
|
|
3
|
-
import { empty } from '@quenk/noni/lib/data/array';
|
|
4
|
-
import {
|
|
5
|
-
CaseFunction,
|
|
6
|
-
Default,
|
|
7
|
-
TypeCase
|
|
8
|
-
} from '@quenk/noni/lib/control/match/case';
|
|
9
|
-
import { identity } from '@quenk/noni/lib/data/function';
|
|
10
|
-
|
|
11
|
-
import { Template } from '../../../../template';
|
|
12
|
-
import { Address, ADDRESS_DISCARD } from '../../../../address';
|
|
13
|
-
import { Task } from '../../scheduler';
|
|
14
|
-
import { Message } from '../../../..';
|
|
15
|
-
import { VM } from '../../';
|
|
16
|
-
import { SharedThread, ThreadState } from '.';
|
|
17
|
-
import { EVENT_ACTOR_RECEIVE, EVENT_MESSAGE_DROPPED } from '../../event';
|
|
18
|
-
|
|
19
|
-
const defaultCases = [new Default(identity)];
|
|
20
|
-
|
|
21
|
-
export const ERR_THREAD_INVALID = 'ERR_THREAD_INVALID';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* JSThread is used by actors that run in the same event loop as the VM.
|
|
25
|
-
*/
|
|
26
|
-
export class JSThread implements SharedThread {
|
|
27
|
-
constructor(
|
|
28
|
-
public vm: VM,
|
|
29
|
-
public address: Address,
|
|
30
|
-
public mailbox: Message[] = [],
|
|
31
|
-
public state: ThreadState = ThreadState.IDLE
|
|
32
|
-
) {}
|
|
33
|
-
|
|
34
|
-
readonly self = this.address;
|
|
35
|
-
|
|
36
|
-
_assertValid() {
|
|
37
|
-
if (!this.isValid()) throw new Error(ERR_THREAD_INVALID);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
isValid() {
|
|
41
|
-
return (
|
|
42
|
-
this.state !== ThreadState.INVALID &&
|
|
43
|
-
this.state !== ThreadState.ERROR
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async start() {}
|
|
48
|
-
|
|
49
|
-
async notify(msg: Message) {
|
|
50
|
-
this._assertValid();
|
|
51
|
-
|
|
52
|
-
this.mailbox.push(msg);
|
|
53
|
-
|
|
54
|
-
if (this.state === ThreadState.MSG_WAIT) this.resume();
|
|
55
|
-
|
|
56
|
-
this.vm.scheduler.run();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async stop() {}
|
|
60
|
-
|
|
61
|
-
async watch<T>(task: () => Promise<T>) {
|
|
62
|
-
this._assertValid();
|
|
63
|
-
await Future.do(task).catch(err => this.raise(err));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async kill(address: Address): Promise<void> {
|
|
67
|
-
this._assertValid();
|
|
68
|
-
this.state = ThreadState.INVALID;
|
|
69
|
-
await this.vm.sendKillSignal(this, address);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
die() {
|
|
73
|
-
// TODO: dispatch event
|
|
74
|
-
this.state = ThreadState.INVALID;
|
|
75
|
-
this.vm.scheduler.removeTasks(this);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* resume marks the Thread as ready to run again.
|
|
80
|
-
*/
|
|
81
|
-
resume() {
|
|
82
|
-
this._assertValid();
|
|
83
|
-
this.state = ThreadState.IDLE;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async raise(e: Err) {
|
|
87
|
-
this._assertValid();
|
|
88
|
-
this.state = ThreadState.ERROR;
|
|
89
|
-
await this.vm.errors.raise(this, e);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async spawn(tmpl: Template): Promise<Address> {
|
|
93
|
-
this._assertValid();
|
|
94
|
-
let result = await Future.fromCallback<Address>(cb => {
|
|
95
|
-
this.vm.scheduler.postTask(
|
|
96
|
-
new Task(this, cb, async () => {
|
|
97
|
-
let address = await this.vm.allocator.allocate(this, tmpl);
|
|
98
|
-
cb(null, address);
|
|
99
|
-
})
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async tell(addr: Address, msg: Message): Promise<void> {
|
|
106
|
-
this._assertValid();
|
|
107
|
-
await Future.fromCallback(cb => {
|
|
108
|
-
this.vm.scheduler.postTask(
|
|
109
|
-
new Task(this, cb, async () => {
|
|
110
|
-
await this.vm.sendMessage(this, addr, msg);
|
|
111
|
-
cb(null);
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async receive<T = Message>(cases: TypeCase<T>[] = []): Promise<T> {
|
|
118
|
-
this._assertValid();
|
|
119
|
-
let msg = await Future.fromCallback<T>(cb => {
|
|
120
|
-
this.vm.events.dispatchActorEvent(
|
|
121
|
-
EVENT_ACTOR_RECEIVE,
|
|
122
|
-
this.address
|
|
123
|
-
);
|
|
124
|
-
let matcher = new CaseFunction(empty(cases) ? defaultCases : cases);
|
|
125
|
-
let task = new Task(this, cb, async () => {
|
|
126
|
-
this._assertValid();
|
|
127
|
-
if (!empty(this.mailbox)) {
|
|
128
|
-
let msg = this.mailbox.shift();
|
|
129
|
-
if (matcher.test(msg)) {
|
|
130
|
-
//XXX: Setting the state to idle here allows for
|
|
131
|
-
// nested tasks.
|
|
132
|
-
this.resume();
|
|
133
|
-
let result = await matcher.apply(msg);
|
|
134
|
-
return cb(null, result);
|
|
135
|
-
}
|
|
136
|
-
this.vm.events.dispatchMessageEvent(
|
|
137
|
-
EVENT_MESSAGE_DROPPED,
|
|
138
|
-
ADDRESS_DISCARD,
|
|
139
|
-
this.address,
|
|
140
|
-
msg
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
this.state = ThreadState.MSG_WAIT;
|
|
144
|
-
this.vm.scheduler.postTask(task, true);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
this.vm.scheduler.postTask(task);
|
|
148
|
-
});
|
|
149
|
-
return msg;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module contains the type of objects used by the VM.
|
|
3
|
-
*
|
|
4
|
-
* The high byte of a stack instruction is used to indicate the type of value.
|
|
5
|
-
* Therefore we can have a max of 255 types. In practice, far less is needed
|
|
6
|
-
* and most non-primitive types should be an object.
|
|
7
|
-
*/
|
|
8
|
-
import { Type } from '@quenk/noni/lib/data/type';
|
|
9
|
-
|
|
10
|
-
import { PTObject } from './object';
|
|
11
|
-
import { Thread } from './thread';
|
|
12
|
-
|
|
13
|
-
export const BYTE_TYPE = 0xff000000;
|
|
14
|
-
export const BYTE_INDEX = 0xffffff;
|
|
15
|
-
|
|
16
|
-
export const TYPE_STEP = 0x1000000;
|
|
17
|
-
|
|
18
|
-
export const TYPE_UINT8 = TYPE_STEP;
|
|
19
|
-
export const TYPE_UINT16 = TYPE_STEP * 2;
|
|
20
|
-
export const TYPE_UINT32 = TYPE_STEP * 3;
|
|
21
|
-
export const TYPE_INT8 = TYPE_STEP * 4;
|
|
22
|
-
export const TYPE_INT16 = TYPE_STEP * 5;
|
|
23
|
-
export const TYPE_INT32 = TYPE_STEP * 6;
|
|
24
|
-
export const TYPE_BOOLEAN = TYPE_STEP * 7;
|
|
25
|
-
export const TYPE_STRING = TYPE_STEP * 8;
|
|
26
|
-
export const TYPE_OBJECT = TYPE_STEP * 9;
|
|
27
|
-
export const TYPE_LIST = TYPE_STEP * 10;
|
|
28
|
-
export const TYPE_FUN = TYPE_STEP * 11;
|
|
29
|
-
export const TYPE_CONS = TYPE_STEP * 12;
|
|
30
|
-
export const TYPE_FOREIGN = TYPE_STEP * 13;
|
|
31
|
-
export const TYPE_VOID = 0xf0000000;
|
|
32
|
-
|
|
33
|
-
export const TYPE_MASK = 0xff000000;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* TypeDescriptor
|
|
37
|
-
*/
|
|
38
|
-
export type TypeDescriptor = number;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* PTValue types.
|
|
42
|
-
*/
|
|
43
|
-
export type PTValue = PTVoid | PTNumber | PTBoolean | PTString | PTObject;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* PTNumber types.
|
|
47
|
-
*/
|
|
48
|
-
export type PTNumber =
|
|
49
|
-
| PTInt8
|
|
50
|
-
| PTInt16
|
|
51
|
-
| PTInt32
|
|
52
|
-
| PTUInt8
|
|
53
|
-
| PTUInt16
|
|
54
|
-
| PTUInt32;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* PTVoid is the absence of a value.
|
|
58
|
-
*/
|
|
59
|
-
export type PTVoid = typeof TYPE_VOID;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* PTInt8 is a signed 8bit integer.
|
|
63
|
-
*/
|
|
64
|
-
export type PTInt8 = number;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* PTInt16 is a signed 16bit integer.
|
|
68
|
-
*/
|
|
69
|
-
export type PTInt16 = number;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* PTInt32 is a signed 32bit integer.
|
|
73
|
-
*/
|
|
74
|
-
export type PTInt32 = number;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* PTUInt8 is an unsigned 8bit integer.
|
|
78
|
-
*/
|
|
79
|
-
export type PTUInt8 = number;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* PTUInt16 is an unsigned 16bit integer.
|
|
83
|
-
*/
|
|
84
|
-
export type PTUInt16 = number;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* PTUInt32 is an unsigned 32bit integer.
|
|
88
|
-
*/
|
|
89
|
-
export type PTUInt32 = number;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* PTBoolean is a boolean value.
|
|
93
|
-
*
|
|
94
|
-
* Zero=false, non-zero=true.
|
|
95
|
-
*/
|
|
96
|
-
export type PTBoolean = number;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* PTString
|
|
100
|
-
*/
|
|
101
|
-
export type PTString = string;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* ForeignFun type.
|
|
105
|
-
*
|
|
106
|
-
* To make the return value available to the VM, push a value onto the stack.
|
|
107
|
-
*/
|
|
108
|
-
export type ForeignFun = (r: Thread, ...args: Type[]) => Type;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* getType from a TypeDescriptor.
|
|
112
|
-
*
|
|
113
|
-
* The highest byte of the 32bit descriptor indicates its type.
|
|
114
|
-
*/
|
|
115
|
-
export const getType = (d: TypeDescriptor): number => d & BYTE_TYPE;
|
package/lib/actor/template.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { Path } from '@quenk/noni/lib/data/record/path';
|
|
2
|
-
import { Err } from '@quenk/noni/lib/control/error';
|
|
3
|
-
import { isFunction, isString } from '@quenk/noni/lib/data/type';
|
|
4
|
-
|
|
5
|
-
import { Runtime } from './system/vm/runtime';
|
|
6
|
-
import { Actor } from './';
|
|
7
|
-
|
|
8
|
-
export const ACTION_RAISE = -0x1;
|
|
9
|
-
export const ACTION_IGNORE = 0x0;
|
|
10
|
-
export const ACTION_RESTART = 0x1;
|
|
11
|
-
export const ACTION_STOP = 0x2;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* TemplateType is the type of actor to create.
|
|
15
|
-
*/
|
|
16
|
-
export type TemplateType = string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* TrapFunc is applied to unhandled errors raised by an actor.
|
|
20
|
-
*
|
|
21
|
-
* The result determines the action to take.
|
|
22
|
-
*/
|
|
23
|
-
export type TrapFunc = (e: Err) => TrapAction;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* TrapAction represents each one of the actions that can be taken after
|
|
27
|
-
* an error has been trapped.
|
|
28
|
-
*
|
|
29
|
-
* These are:
|
|
30
|
-
*
|
|
31
|
-
* 1. Raise an error (to the actor's parent).
|
|
32
|
-
* 2. Ignore the error (effectively continuing as though nothing happened).
|
|
33
|
-
* 3. Restart the actor.
|
|
34
|
-
* 4. Stop the actor and eject it from the system.
|
|
35
|
-
*/
|
|
36
|
-
export type TrapAction = -0x1 | 0x0 | 0x1 | 0x2;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* BaseTemplate holds the common properties for all templates.
|
|
40
|
-
*/
|
|
41
|
-
export interface BaseTemplate {
|
|
42
|
-
/**
|
|
43
|
-
* type indicates the type of template and thus the type of thread that
|
|
44
|
-
* will be allocated for the actor.
|
|
45
|
-
*
|
|
46
|
-
* Defaults to 'shared' if not specified.
|
|
47
|
-
*/
|
|
48
|
-
type?: TemplateType;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* id of the actor used when constructing its address.
|
|
52
|
-
*
|
|
53
|
-
* Ids must be unique among the children of an actor but not necessary at
|
|
54
|
-
* the system level.
|
|
55
|
-
*
|
|
56
|
-
* If no id is supplied the system will generate one.
|
|
57
|
-
*/
|
|
58
|
-
id?: string;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* group assignment for the actor.
|
|
62
|
-
*
|
|
63
|
-
* Including an actor in a group allows for messages to be sent to one
|
|
64
|
-
* address but received by multiple actors.
|
|
65
|
-
*/
|
|
66
|
-
group?: string | string[];
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* trap is called when unhandled errors are detected.
|
|
70
|
-
*
|
|
71
|
-
* The result of this function determines the next action to take.
|
|
72
|
-
*/
|
|
73
|
-
trap?: TrapFunc;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* CreateFunc is a function that creates an actor given the handle the system
|
|
78
|
-
* has generated.
|
|
79
|
-
*
|
|
80
|
-
* Use it when a class based actor implementation is preffered.
|
|
81
|
-
*/
|
|
82
|
-
export type CreateFunc = (runtime: Runtime) => Actor;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* RunFunc serves as the main function for function based actors.
|
|
86
|
-
*
|
|
87
|
-
* This should only ever be a function declared with the "async" keyword and
|
|
88
|
-
* not just a function that returns a Promise.
|
|
89
|
-
*/
|
|
90
|
-
export type RunFunc = (runtime: Runtime) => Promise<void>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Template is an object that tells the system how to create an manage an
|
|
94
|
-
* actor.
|
|
95
|
-
*
|
|
96
|
-
* Every actor in the system is created from an initial template that is reused
|
|
97
|
-
* if the actor needs to be restarted. The type of template determines the
|
|
98
|
-
* type of thread that will be allocated for the actor.
|
|
99
|
-
*/
|
|
100
|
-
export type Template = SharedTemplate | ProcessTemplate;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* SharedTemplate is used for resident actors that require a SharedThread to
|
|
104
|
-
* be allocated.
|
|
105
|
-
*/
|
|
106
|
-
export type SharedTemplate = SharedCreateTemplate | SharedRunTemplate;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* SharedCreateTemplate is used for class based actors.
|
|
110
|
-
*/
|
|
111
|
-
export interface SharedCreateTemplate extends BaseTemplate {
|
|
112
|
-
/**
|
|
113
|
-
* create an instance of the actor to be used within the system.
|
|
114
|
-
*/
|
|
115
|
-
create: CreateFunc;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* SharedRunTemplate is used for function based actors.
|
|
120
|
-
*/
|
|
121
|
-
export interface SharedRunTemplate extends BaseTemplate {
|
|
122
|
-
/**
|
|
123
|
-
* run is called to run a function based actor.
|
|
124
|
-
*/
|
|
125
|
-
run: RunFunc;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* ProcessTemplate is used for creating child process actors.
|
|
130
|
-
*/
|
|
131
|
-
export interface ProcessTemplate extends BaseTemplate {
|
|
132
|
-
/**
|
|
133
|
-
* script is the path to the script that will be executed in the child
|
|
134
|
-
* process.
|
|
135
|
-
*/
|
|
136
|
-
script: Path;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Spawnable allows a CreateFunc to be used in place of a Template.
|
|
141
|
-
*/
|
|
142
|
-
export type Spawnable = Template | CreateFunc | RunFunc;
|
|
143
|
-
|
|
144
|
-
const AsyncFunction = (async () => {}).constructor;
|
|
145
|
-
|
|
146
|
-
const isAsyncFunction = (func: Function) => func.constructor === AsyncFunction;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* isProcessTemplate test.
|
|
150
|
-
*/
|
|
151
|
-
export const isProcessTemplate = (tmpl: Template): tmpl is ProcessTemplate =>
|
|
152
|
-
isString((<ProcessTemplate>tmpl).script);
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* fromSpawnable converts a Spawnable to a Template.
|
|
156
|
-
*
|
|
157
|
-
* If a function is supplied we assume a SharedTemplate is desired.
|
|
158
|
-
*
|
|
159
|
-
* NOTE: That this requires a runtime that has an AsyncFunction constructor
|
|
160
|
-
* in global scope in order to work properly.
|
|
161
|
-
*/
|
|
162
|
-
export const fromSpawnable = (tmpl: Spawnable): Template => {
|
|
163
|
-
if (isFunction(tmpl)) {
|
|
164
|
-
return isAsyncFunction(tmpl)
|
|
165
|
-
? { run: <RunFunc>tmpl }
|
|
166
|
-
: { create: <CreateFunc>tmpl };
|
|
167
|
-
} else {
|
|
168
|
-
return tmpl;
|
|
169
|
-
}
|
|
170
|
-
};
|
package/lib/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": "src",
|
|
4
|
-
"lib": ["es5", "ES2015", "DOM"],
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"target": "ES2017",
|
|
7
|
-
"rootDir": ".",
|
|
8
|
-
"outDir": "../lib",
|
|
9
|
-
"moduleResolution": "node",
|
|
10
|
-
"allowUnreachableCode": true,
|
|
11
|
-
"noUnusedParameters": true,
|
|
12
|
-
"noUnusedLocals": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"noImplicitAny": true,
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"declaration": true,
|
|
17
|
-
"strict": true,
|
|
18
|
-
"types": ["node"],
|
|
19
|
-
"typeRoots": ["../node_modules/@types"]
|
|
20
|
-
},
|
|
21
|
-
"exclude": ["node_modules"]
|
|
22
|
-
}
|