From ff932b411d63269dbd4d30ea6bd0aa5160fd8aff Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 9 Oct 2021 22:37:19 +0200 Subject: 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. --- core/modules.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/modules.rs') diff --git a/core/modules.rs b/core/modules.rs index 2af09057f..31e03196a 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -722,6 +722,7 @@ impl ModuleMap { #[cfg(test)] mod tests { use super::*; + use crate::ops::OpCall; use crate::serialize_op_result; use crate::JsRuntime; use crate::Op; @@ -1009,7 +1010,7 @@ mod tests { let (control, _): (u8, ()) = payload.deserialize().unwrap(); assert_eq!(control, 42); let resp = (0, 1, serialize_op_result(Ok(43), state)); - Op::Async(Box::pin(futures::future::ready(resp))) + Op::Async(OpCall::ready(resp)) }; let mut runtime = JsRuntime::new(RuntimeOptions { -- cgit v1.2.3