Explorar el Código

Added delay().

Eugene Lazutkin hace 7 años
padre
commit
8404477337
Se han modificado 1 ficheros con 12 adiciones y 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};