Last active
          March 25, 2025 13:10 
        
      - 
      
 - 
        
Save joepie91/2664c85a744e6bd0629c to your computer and use it in GitHub Desktop.  
    ES6 Promise.delay
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | module.exports = function(duration) { | |
| return function(){ | |
| return new Promise(function(resolve, reject){ | |
| setTimeout(function(){ | |
| resolve(); | |
| }, duration) | |
| }); | |
| }; | |
| }; | |
| // Usage: | |
| var delayPromise = require("./delay-promise"); | |
| doThing() | |
| .then(...) | |
| .then(delayPromise(5000)) | |
| .then(...) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
For nodeJS only