Skip to content

Commit

Permalink
feat: delay
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Jan 20, 2024
1 parent ecdf62c commit 194df85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ export function utParse(ds:string):number{
const [y, m, d, h, mi, s] = ds.split(/[/ :TZ_.-]/i).map(v => Number(v));

return utEncode(new Date(y, (m ?? 1) - 1, d ?? 1, h ?? 0, mi ?? 0, s ?? 0));
}

/**
* Wait for specified time.
* @example
* ```ts
* await delay(1000);
* ```
*/
export async function delay(ms:number):Promise<void>{
await new Promise<void>(done => setTimeout(done, ms));
}
9 changes: 8 additions & 1 deletion test/time.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {assertEquals} from "../deps.test.ts";
import {utEncode, utDecode, utParse} from "../src/time.ts";
import {utEncode, utDecode, utParse, delay} from "../src/time.ts";

const sample = new Date(2000, 0, 1, 0, 0, 0, 0);

Expand All @@ -20,4 +20,11 @@ Deno.test({

assertEquals(result, 946684800);
}
});

Deno.test({
name: "Time: Delay",
async fn(){
await delay(100);
}
});

0 comments on commit 194df85

Please sign in to comment.