-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only accessible from Rust currently.
- Loading branch information
Showing
9 changed files
with
367 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as dispatch from "./dispatch"; | ||
import * as msg from "gen/msg_generated"; | ||
import * as flatbuffers from "./flatbuffers"; | ||
import { window } from "./globals"; | ||
import { libdeno } from "./libdeno"; | ||
import { assert, log, setLogDebug } from "./util"; | ||
|
||
export async function postMessage(data: Uint8Array): Promise<void> { | ||
const builder = flatbuffers.createBuilder(); | ||
msg.WorkerPostMessage.startWorkerPostMessage(builder); | ||
const inner = msg.WorkerPostMessage.endWorkerPostMessage(builder); | ||
const baseRes = await dispatch.sendAsync( | ||
builder, | ||
msg.Any.WorkerPostMessage, | ||
inner, | ||
data | ||
); | ||
assert(baseRes != null); | ||
} | ||
|
||
export async function getMessage(): Promise<null | Uint8Array> { | ||
log("getMessage"); | ||
// Send CodeFetch message | ||
const builder = flatbuffers.createBuilder(); | ||
msg.WorkerGetMessage.startWorkerGetMessage(builder); | ||
const inner = msg.WorkerGetMessage.endWorkerGetMessage(builder); | ||
const baseRes = await dispatch.sendAsync( | ||
builder, | ||
msg.Any.WorkerGetMessage, | ||
inner | ||
); | ||
assert(baseRes != null); | ||
assert( | ||
msg.Any.WorkerGetMessageRes === baseRes!.innerType(), | ||
`base.innerType() unexpectedly is ${baseRes!.innerType()}` | ||
); | ||
const res = new msg.WorkerGetMessageRes(); | ||
assert(baseRes!.inner(res) != null); | ||
|
||
const dataArray = res.dataArray(); | ||
if (dataArray == null) { | ||
return null; | ||
} else { | ||
return new Uint8Array(dataArray!); | ||
} | ||
} | ||
|
||
let isClosing = false; | ||
|
||
export function workerClose(): void { | ||
isClosing = true; | ||
} | ||
|
||
export async function workerMain() { | ||
libdeno.recv(dispatch.handleAsyncMsgFromRust); | ||
setLogDebug(true); | ||
log("workerMain"); | ||
|
||
while (!isClosing) { | ||
let data = await getMessage(); | ||
if (data == null) { | ||
log("workerMain got null message. quitting."); | ||
break; | ||
} | ||
if (window["onmessage"]) { | ||
let event = { data }; | ||
window.onmessage(event); | ||
} else { | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.