Commit 5e27716d8e786b828fdcca57bc8500211391b19a
1 parent
5326735c91
Exists in
master
sleepMs promise
Showing 1 changed file with 8 additions and 3 deletions Side-by-side Diff
lib/webhook-sender.js
... | ... | @@ -22,6 +22,12 @@ if (!fs.existsSync(baseDumpDir)) { |
22 | 22 | } |
23 | 23 | const lastDumpFileName = path.join(baseDumpDir, 'last'); |
24 | 24 | |
25 | +const sleepMs = (ms) => new Promise((resolve) => { | |
26 | + setTimeout(() => { | |
27 | + resolve(); | |
28 | + }, ms); | |
29 | +}); | |
30 | + | |
25 | 31 | const dumper = async (xid, webhookType, body) => { |
26 | 32 | if (!config.webhook || !config.webhook.dump) { |
27 | 33 | return; |
... | ... | @@ -81,9 +87,8 @@ const sender = async (xid, webhookType, body, retry) => { |
81 | 87 | return; |
82 | 88 | } |
83 | 89 | |
84 | - setTimeout(() => { | |
85 | - sender(xid, webhookType, body, (retry || 0) + 1); | |
86 | - }, sleepBeforeRetryMs); | |
90 | + await sleepMs(sleepBeforeRetryMs); | |
91 | + sender(xid, webhookType, body, (retry || 0) + 1); | |
87 | 92 | } |
88 | 93 | }; |
89 | 94 | module.exports = sender; |