mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
parent
aa691ea26c
commit
99e2c42d16
1 changed files with 47 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
import { test, assertEqual } from "./test_util.ts";
|
import { test, assertEqual } from "./test_util.ts";
|
||||||
|
|
||||||
function deferred() {
|
function deferred() {
|
||||||
|
@ -30,6 +31,28 @@ test(async function timeoutSuccess() {
|
||||||
assertEqual(count, 1);
|
assertEqual(count, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(async function timeoutArgs() {
|
||||||
|
let arg = 1;
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
setTimeout(
|
||||||
|
(a, b, c) => {
|
||||||
|
try {
|
||||||
|
assertEqual(a, arg);
|
||||||
|
assertEqual(b, arg.toString());
|
||||||
|
assertEqual(c, [arg]);
|
||||||
|
resolve();
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
10,
|
||||||
|
arg,
|
||||||
|
arg.toString(),
|
||||||
|
[arg]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test(async function timeoutCancelSuccess() {
|
test(async function timeoutCancelSuccess() {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const id = setTimeout(() => {
|
const id = setTimeout(() => {
|
||||||
|
@ -91,6 +114,30 @@ test(async function intervalCancelSuccess() {
|
||||||
assertEqual(count, 0);
|
assertEqual(count, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(async function intervalCancelSuccess2() {
|
||||||
|
const timers = [];
|
||||||
|
let timeouts = 0;
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
timers[i] = setTimeout(onTimeout, 20 * i);
|
||||||
|
}
|
||||||
|
function onTimeout() {
|
||||||
|
++timeouts;
|
||||||
|
for (let i = 1; i < timers.length; i++) {
|
||||||
|
clearTimeout(timers[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
try {
|
||||||
|
assertEqual(timeouts, 1);
|
||||||
|
resolve();
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test(async function intervalCancelInvalidSilentFail() {
|
test(async function intervalCancelInvalidSilentFail() {
|
||||||
// Should silently fail (no panic)
|
// Should silently fail (no panic)
|
||||||
clearInterval(2147483647);
|
clearInterval(2147483647);
|
||||||
|
|
Loading…
Add table
Reference in a new issue