2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-08 08:09:22 -04:00
|
|
|
import * as minimal from "./ops/dispatch_minimal.ts";
|
|
|
|
import * as json from "./ops/dispatch_json.ts";
|
2019-12-05 15:30:20 -05:00
|
|
|
import { AsyncHandler } from "./plugins.ts";
|
2018-09-05 22:13:36 -04:00
|
|
|
|
2019-12-05 15:30:20 -05:00
|
|
|
const PLUGIN_ASYNC_HANDLER_MAP: Map<number, AsyncHandler> = new Map();
|
|
|
|
|
|
|
|
export function setPluginAsyncHandler(
|
|
|
|
opId: number,
|
|
|
|
handler: AsyncHandler
|
|
|
|
): void {
|
|
|
|
PLUGIN_ASYNC_HANDLER_MAP.set(opId, handler);
|
|
|
|
}
|
2019-05-03 00:06:43 -04:00
|
|
|
|
2020-01-17 08:26:11 -05:00
|
|
|
export function getAsyncHandler(opName: string): (msg: Uint8Array) => void {
|
|
|
|
switch (opName) {
|
2020-02-25 09:14:27 -05:00
|
|
|
case "op_write":
|
|
|
|
case "op_read":
|
2020-01-17 08:26:11 -05:00
|
|
|
return minimal.asyncMsgFromRust;
|
2019-08-21 20:42:48 -04:00
|
|
|
default:
|
2020-01-17 08:26:11 -05:00
|
|
|
return json.asyncMsgFromRust;
|
2018-08-30 15:35:51 -04:00
|
|
|
}
|
|
|
|
}
|