-
Notifications
You must be signed in to change notification settings - Fork 1
/
HelloWorldComChannelEndpointWorker.ts
41 lines (33 loc) · 1.14 KB
/
HelloWorldComChannelEndpointWorker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { RawPayload, WorkerMessage, ComRouter, ComChannelEndpoint } from 'wtd-core';
/// <reference lib="WebWorker" />
declare const self: DedicatedWorkerGlobalScope;
class ExampleComRouterWorker implements ComRouter {
private endpointFs?: ComChannelEndpoint;
setComChannelEndpoint(comChannelEndpoint: ComChannelEndpoint): void {
this.endpointFs = comChannelEndpoint;
}
async hello_world(message: WorkerMessage) {
// burn some time
for (let i = 0; i < 25000000; i++) {
i++;
}
await this.endpointFs?.sentAnswer({
message: WorkerMessage.createFromExisting(message, {
overrideCmd: 'hello_world_confirm',
overridePayloads: new RawPayload({
hello: 'Hello! I just incremented "i" 25 million times.'
})
}),
awaitAnswer: false
});
}
}
new ComChannelEndpoint({
endpointId: 2000,
endpointConfig: {
$type: 'DirectImplConfig',
impl: self
},
verbose: true,
endpointName: 'HelloWorldComChannelEndpointWorker'
}).connect(new ExampleComRouterWorker());