From 30bc7fecc6cfd1179382969a642f893c2f92de48 Mon Sep 17 00:00:00 2001 From: c-antin <38494182+c-antin@users.noreply.github.com> Date: Tue, 11 Jul 2023 17:23:31 +0200 Subject: [PATCH] test promise --- mod_test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mod_test.ts b/mod_test.ts index 204749e..fc6451f 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -1,6 +1,25 @@ import { assertEquals } from "https://deno.land/std@0.193.0/testing/asserts.ts"; import { Future } from "./mod.ts"; +Deno.test("promise", async () => { + let n = 0; + //promise runs immediately + const promise = new Promise((resolve) => { + n++; + console.log("executor", n); + resolve(n); + }); + console.log(promise); + assertEquals(n, 1); + + { + const m = await promise; + assertEquals(m, 1); + } + console.log(promise); + assertEquals(n, 1); +}); + Deno.test("await", async () => { let n = 0; const future = new Future((resolve) => {