-
Notifications
You must be signed in to change notification settings - Fork 652
Expand file tree
/
Copy pathChildProcessSnapExecutor.ts
More file actions
26 lines (22 loc) · 977 Bytes
/
ChildProcessSnapExecutor.ts
File metadata and controls
26 lines (22 loc) · 977 Bytes
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
import ObjectMultiplex from '@metamask/object-multiplex';
import { ProcessMessageStream } from '@metamask/post-message-stream/node';
import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';
import { pipeline } from 'readable-stream';
import { BaseSnapExecutor } from '../common/BaseSnapExecutor';
import { log } from '../logging';
export class ChildProcessSnapExecutor extends BaseSnapExecutor {
static initialize() {
log('Worker: Connecting to parent.');
const parentStream = new ProcessMessageStream();
const mux = new ObjectMultiplex();
pipeline(parentStream, mux as any, parentStream, (error) => {
if (error) {
logError(`Parent stream failure, closing worker.`, error);
}
self.close();
});
const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);
const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC) as any;
return new ChildProcessSnapExecutor(commandStream, rpcStream);
}
}