From 6071192aed6a1a160d150bef87f4a550b54efec4 Mon Sep 17 00:00:00 2001 From: qq_20735085 Date: Tue, 26 Mar 2024 10:41:00 +0800 Subject: [PATCH] Tue Mar 26 10:41:00 CST 2024 inscode --- index.js | 9 ++++++++- test.js | 10 ---------- 2 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 test.js diff --git a/index.js b/index.js index 2ff5efc..9b2b1a9 100644 --- a/index.js +++ b/index.js @@ -15,4 +15,11 @@ async function loopWithPromise(count, duration, callback) { } } -module.exports.loopWithPromise = loopWithPromise; \ No newline at end of file +(async () => { + // 一定要加上 await,可以实现调用点阻塞 + await loopWithPromise(5, 300, (count) => { + console.log("执行次数: " + count); + }); + + console.log("执行完成!"); +})(); \ No newline at end of file diff --git a/test.js b/test.js deleted file mode 100644 index 56b4411..0000000 --- a/test.js +++ /dev/null @@ -1,10 +0,0 @@ -const { loopWithPromise } = require('./index'); - -(async () => { - // 一定要加上 await - await loopWithPromise(5, 300, (count) => { - console.log("执行次数: " + count); - }); - - console.log("执行完成!"); -})(); \ No newline at end of file -- GitLab