2020-05-09 08:34:47 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-05-15 16:59:44 -04:00
|
|
|
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
|
2020-05-09 08:34:47 -04:00
|
|
|
import { deferred } from "./deferred.ts";
|
|
|
|
|
2020-05-15 16:59:44 -04:00
|
|
|
Deno.test("[async] deferred: resolve", async function (): Promise<void> {
|
|
|
|
const d = deferred<string>();
|
|
|
|
d.resolve("🦕");
|
|
|
|
assertEquals(await d, "🦕");
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("[async] deferred: reject", async function (): Promise<void> {
|
2020-05-09 08:34:47 -04:00
|
|
|
const d = deferred<number>();
|
2020-05-15 16:59:44 -04:00
|
|
|
d.reject(new Error("A deno error 🦕"));
|
|
|
|
await assertThrowsAsync(async () => {
|
|
|
|
await d;
|
|
|
|
});
|
2020-05-09 08:34:47 -04:00
|
|
|
});
|