#Add Resource to resource table at bootstrap

10 messages · Page 1 of 1 (latest)

plain harbor
#

I played around with deno_core and tried to add a tcp stream to the resource table when bootstrapping the worker. I somehow got it working, but i feel like that this is not the way to go, and just want to ask if you have better solutions for this.

What i did is basically copying https://github.com/denoland/deno/blob/main/core/examples/http_bench_json_ops.rs#L84-L117 and wrapping everything in a Rc and making it cloneable. Then i bootstrap the runtime by using my custom stream struct and cloning it into the resource table. Is this somewhat of a sensible solution?

Code can be found here: https://gist.github.com/DreamTexX/998d7ccb1664414efc7fc9b44ab6cb74

main.js looks like this:

let data = new Uint8Array(100);
await Deno.core.read(3, data);
Deno.core.print(new TextDecoder().decode(data));
raw stirrup
#
let worker = MainWorker::bootstrap_from_options(...)
let op_state = worker.js_runtime.op_state();
op_state.borrow_mut().resource_table.add(...)
#

no need to go with the extension way if you just need to add a single resource

plain harbor
#

Ohhhhh wow

#

Wasted so many time on this thank you so much xD

raw stirrup
#

no problem!

plain harbor
#

Is there also a better way for converting the tcpstream into a resource or do i need to do what was in the example?

raw stirrup
#

that seems sane way

#

we do the same in deno itself IIRC

#

so you can consider it "canonical" 🙂 though our use cases might be different