Browse Source

storage-node: check stat completion on next tick

Mokhtar Naamani 3 năm trước cách đây
mục cha
commit
2612029c2e

+ 2 - 2
storage-node/packages/colossus/lib/sync.js

@@ -21,7 +21,7 @@
 const debug = require('debug')('joystream:sync')
 const _ = require('lodash')
 const { ContentId } = require('@joystream/types/storage')
-const { sleep } = require('@joystream/storage-utils/sleep')
+const { nextTick } = require('@joystream/storage-utils/sleep')
 
 // The number of concurrent items to attemp to fetch. Must be greater than zero.
 const MAX_CONCURRENT_SYNC_ITEMS = 30
@@ -69,7 +69,7 @@ async function syncContent({ api, storage, contentBeingSynced, contentCompleteSy
 
       // Allow short time for checking if content is already stored locally.
       // So we can handle more new items per run.
-      await sleep(50)
+      await nextTick()
     } catch (err) {
       // Most likely failed to resolve the content id
       debug(`Failed calling synchronize ${err}`)

+ 7 - 0
storage-node/packages/util/sleep.js

@@ -4,6 +4,13 @@ function sleep(ms) {
   })
 }
 
+function nextTick() {
+  return new Promise((resolve) => {
+    process.nextTick(resolve)
+  })
+}
+
 module.exports = {
   sleep,
+  nextTick,
 }