summaryrefslogtreecommitdiff
path: root/ext/net
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2021-10-09 22:37:19 +0200
committerBert Belder <bertbelder@gmail.com>2021-10-17 19:50:42 +0200
commitff932b411d63269dbd4d30ea6bd0aa5160fd8aff (patch)
tree5dad617aea815c4145262860d6e3b5115224ab92 /ext/net
parentff95fc167d7124f3c7f2c6951070e2c40701cf32 (diff)
fix(core): poll async ops eagerly (#12385)
Currently all async ops are polled lazily, which means that op initialization code is postponed until control is yielded to the event loop. This has some weird consequences, e.g. ```js let listener = Deno.listen(...); let conn_promise = listener.accept(); listener.close(); // `BadResource` is thrown. A reasonable error would be `Interrupted`. let conn = await conn_promise; ``` JavaScript promises are expected to be eagerly evaluated. This patch makes ops actually do that.
Diffstat (limited to 'ext/net')
-rw-r--r--ext/net/01_net.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/ext/net/01_net.js b/ext/net/01_net.js
index cc10a1c0a..39df5a9d4 100644
--- a/ext/net/01_net.js
+++ b/ext/net/01_net.js
@@ -3,7 +3,7 @@
((window) => {
const core = window.Deno.core;
- const { BadResource } = core;
+ const { BadResource, Interrupted } = core;
const {
PromiseResolve,
SymbolAsyncIterator,
@@ -124,7 +124,7 @@
try {
conn = await this.accept();
} catch (error) {
- if (error instanceof BadResource) {
+ if (error instanceof BadResource || error instanceof Interrupted) {
return { value: undefined, done: true };
}
throw error;
@@ -191,7 +191,7 @@
try {
yield await this.receive();
} catch (err) {
- if (err instanceof BadResource) {
+ if (err instanceof BadResource || err instanceof Interrupted) {
break;
}
throw err;