summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorandy finch <andyfinch7@gmail.com>2019-04-05 15:57:59 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-04-05 22:57:59 +0300
commit7a3df0a18465ceebe43f3183daa2f9397c4e5ebb (patch)
tree64fb338c99cda0be406c9fb0788c88fc97c0a7be /js
parent031411b449b1990241c0ff0565e01e60f30b769a (diff)
Add worker benchmarks (#2059)
Diffstat (limited to 'js')
-rw-r--r--js/workers.ts9
1 files changed, 8 insertions, 1 deletions
diff --git a/js/workers.ts b/js/workers.ts
index 601ffa0b1..8c08a8506 100644
--- a/js/workers.ts
+++ b/js/workers.ts
@@ -150,11 +150,13 @@ export interface Worker {
onmessage?: (e: { data: any }) => void;
onmessageerror?: () => void;
postMessage(data: any): void;
+ closed: Promise<void>;
}
export class WorkerImpl implements Worker {
private readonly rid: number;
private isClosing: boolean = false;
+ private readonly isClosedPromise: Promise<void>;
public onerror?: () => void;
public onmessage?: (data: any) => void;
public onmessageerror?: () => void;
@@ -162,11 +164,16 @@ export class WorkerImpl implements Worker {
constructor(specifier: string) {
this.rid = createWorker(specifier);
this.run();
- hostGetWorkerClosed(this.rid).then(() => {
+ this.isClosedPromise = hostGetWorkerClosed(this.rid);
+ this.isClosedPromise.then(() => {
this.isClosing = true;
});
}
+ get closed(): Promise<void> {
+ return this.isClosedPromise;
+ }
+
postMessage(data: any): void {
hostPostMessage(this.rid, data);
}