-
Notifications
You must be signed in to change notification settings - Fork 0
delay
김태헌 edited this page Sep 26, 2024
·
5 revisions
import { delay } from 'mori-ts';
const result = await delay(1000, 1);
console.log(result); // 1초 대기 후 출력: 1
import { delay } from 'mori-ts';
const result = await delay(1000);
console.log(result); // 1초 대기 후 출력: undefined
import { map, pipe, toArray, toAsync, delay } from 'mori-ts';
const start = Date.now();
const res = await pipe(
[1, 2, 3],
toAsync,
map(value => delay(1000, value)),
toArray,
);
const end = Date.now();
console.log(res); // 각 요소를 1초씩 대기 후 출력: [1, 2, 3]
console.log(`Elapsed time: ${end - start}ms`); // time: 약 3000ms
https://github.com/gangnamssal/mori-ts/blob/main/src/test/delay.spec.ts