From 6984b63f2f3c8d0819fe2dced8252a81f3400ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 16 Dec 2020 17:14:12 +0100 Subject: refactor: rewrite ops to use ResourceTable2 (#8512) This commit migrates all ops to use new resource table and "AsyncRefCell". Old implementation of resource table was completely removed and all code referencing it was updated to use new system. --- runtime/rt/30_net.js | 32 +++++++------------------------- runtime/rt/40_fs_events.js | 2 ++ runtime/rt/40_signals.js | 11 ++++++++++- 3 files changed, 19 insertions(+), 26 deletions(-) (limited to 'runtime/rt') diff --git a/runtime/rt/30_net.js b/runtime/rt/30_net.js index 9a71f0693..7009f6f8d 100644 --- a/runtime/rt/30_net.js +++ b/runtime/rt/30_net.js @@ -11,20 +11,16 @@ 0: "Read", 1: "Write", 2: "ReadWrite", - Read: 0, + Read: 0, // TODO: nonsense, remove me. Write: 1, ReadWrite: 2, // unused }; function shutdown(rid, how) { - core.jsonOpSync("op_shutdown", { rid, how }); - return Promise.resolve(); + return core.jsonOpAsync("op_shutdown", { rid, how }); } - function opAccept( - rid, - transport, - ) { + function opAccept(rid, transport) { return core.jsonOpAsync("op_accept", { rid, transport }); } @@ -36,11 +32,7 @@ return core.jsonOpAsync("op_connect", args); } - function opReceive( - rid, - transport, - zeroCopy, - ) { + function opReceive(rid, transport, zeroCopy) { return core.jsonOpAsync( "op_datagram_receive", { rid, transport }, @@ -56,11 +48,7 @@ #rid = 0; #remoteAddr = null; #localAddr = null; - constructor( - rid, - remoteAddr, - localAddr, - ) { + constructor(rid, remoteAddr, localAddr) { this.#rid = rid; this.#remoteAddr = remoteAddr; this.#localAddr = localAddr; @@ -149,11 +137,7 @@ #rid = 0; #addr = null; - constructor( - rid, - addr, - bufSize = 1024, - ) { + constructor(rid, addr, bufSize = 1024) { this.#rid = rid; this.#addr = addr; this.bufSize = bufSize; @@ -213,9 +197,7 @@ return new Listener(res.rid, res.localAddr); } - async function connect( - options, - ) { + async function connect(options) { let res; if (options.transport === "unix") { diff --git a/runtime/rt/40_fs_events.js b/runtime/rt/40_fs_events.js index a36adecba..a179e8c1b 100644 --- a/runtime/rt/40_fs_events.js +++ b/runtime/rt/40_fs_events.js @@ -24,6 +24,8 @@ } catch (error) { if (error instanceof errors.BadResource) { return { value: undefined, done: true }; + } else if (error instanceof errors.Interrupted) { + return { value: undefined, done: true }; } throw error; } diff --git a/runtime/rt/40_signals.js b/runtime/rt/40_signals.js index 739c963fd..091afd66a 100644 --- a/runtime/rt/40_signals.js +++ b/runtime/rt/40_signals.js @@ -3,6 +3,7 @@ ((window) => { const core = window.Deno.core; const { build } = window.__bootstrap.build; + const { errors } = window.__bootstrap.errors; function bindSignal(signo) { return core.jsonOpSync("op_signal_bind", { signo }); @@ -212,7 +213,15 @@ } #pollSignal = async () => { - const res = await pollSignal(this.#rid); + let res; + try { + res = await pollSignal(this.#rid); + } catch (error) { + if (error instanceof errors.BadResource) { + return true; + } + throw error; + } return res.done; }; -- cgit v1.2.3