Explorar o código

Added delay().

Eugene Lazutkin %!s(int64=7) %!d(string=hai) anos
pai
achega
8404477337
Modificáronse 1 ficheiros con 12 adicións e 1 borrados
  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};