@mercuryworkshop/bare-mux
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -60,4 +60,4 @@ import { BareHeaders } from './baretypes'; | ||
getTransport(): Promise<string>; | ||
setTransport(path: string, options: any[]): Promise<void>; | ||
setManualTransport(functionBody: string): Promise<void>; | ||
setTransport(path: string, options: any[], transferables?: Transferable[]): Promise<void>; | ||
setManualTransport(functionBody: string, options: any[], transferables?: Transferable[]): Promise<void>; | ||
getInnerPort(): MessagePort | Promise<MessagePort>; | ||
@@ -64,0 +64,0 @@ } |
@@ -17,3 +17,6 @@ import { BareHeaders, TransferrableResponse } from "./baretypes"; | ||
}; | ||
client?: string; | ||
client?: { | ||
function: string; | ||
args: any[]; | ||
}; | ||
}; | ||
@@ -20,0 +23,0 @@ export type WorkerRequest = { |
@@ -199,13 +199,16 @@ (function (global, factory) { | ||
} | ||
async setTransport(path, options) { | ||
async setTransport(path, options, transferables) { | ||
await this.setManualTransport(` | ||
const { default: BareTransport } = await import("${path}"); | ||
return [new BareTransport(${options.map(x => JSON.stringify(x)).join(", ")}), "${path}"]; | ||
`); | ||
return [BareTransport, "${path}"]; | ||
`, options, transferables); | ||
} | ||
async setManualTransport(functionBody) { | ||
async setManualTransport(functionBody, options, transferables) { | ||
await this.worker.sendMessage({ | ||
type: "set", | ||
client: functionBody, | ||
}); | ||
client: { | ||
function: functionBody, | ||
args: options, | ||
}, | ||
}, transferables); | ||
} | ||
@@ -212,0 +215,0 @@ getInnerPort() { |
@@ -50,5 +50,5 @@ (function () { | ||
// @ts-expect-error | ||
const func = new AsyncFunction(message.client); | ||
const func = new AsyncFunction(message.client.function); | ||
const [newTransport, name] = await func(); | ||
currentTransport = newTransport; | ||
currentTransport = new newTransport(...message.client.args); | ||
currentTransportName = name; | ||
@@ -55,0 +55,0 @@ console.log("set transport to ", currentTransport, name); |
{ | ||
"name": "@mercuryworkshop/bare-mux", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
90557
1217