-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathprocess.js
55 lines (48 loc) · 1.38 KB
/
process.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Process with signal support.
* @suppress {moduleLoad}
* @suppress {checkTypes} module$__$wasi_js_bindings$js naming confusion.
*/
import {Process} from '../../wasi-js-bindings/index.js';
/**
* Background process w/wassh extensions.
*
* We aren't customizing it currently, but we might in the future, so provide a
* name now to avoid rewriting symbols in the future.
*/
export class Foreground extends Process.Foreground {}
/**
* Background process w/wassh extensions.
*/
export class Background extends Process.Background {
constructor(...args) {
super(...args);
/** @const {!Array<number>} */
this.signal_queue = [];
}
/**
* Send (queue) a signal for the process.
*
* @param {number} signum The signal to send. This uses musl ABI for signal
* numbers, not WASI ABI.
*/
send_signal(signum) {
this.signal_queue.push(signum);
if (this.handler.notify_) {
this.handler.notify_();
}
}
/**
* Write data to the plugin.
*
* @param {number} fd The file handle to write to.
* @param {!ArrayBuffer} buf The content to write.
* @return {!WASI_t.errno|{nwritten: !WASI_t.size}}
*/
async writeTo(fd, buf) {
return this.handler.handle_fd_write(fd, buf);
}
}