Browse Source

Added delay().

Eugene Lazutkin 7 năm trước cách đây
mục cha
commit
8404477337
1 tập tin đã thay đổi với 12 bổ sung1 xóa
  1. 12 1
      tests/helpers.js

+ 12 - 1
tests/helpers.js

@@ -20,4 +20,15 @@ const streamToArray = array =>
     }
   });
 
-module.exports = {streamFromArray, streamToArray};
+const delay = (fn, ms = 20) => async (...args) =>
+  new Promise((resolve, reject) => {
+    setTimeout(() => {
+      try {
+        resolve(fn(...args));
+      } catch (error) {
+        reject(error);
+      }
+    }, ms);
+  });
+
+module.exports = {streamFromArray, streamToArray, delay};