JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/2.9.3/bluebird.min.js"></script>
JavaScript
function makeCallWith3SecondLatency(cb) {
console.log('mocking a call with 3 second latency...');
var mockResult = 'the result';
setTimeout(function() { cb(mockResult); }, 3000);
}
function stallPromise(promise, delay) {
return Promise.delay(delay).return(promise);
}
function doSomethingAsync(minDelay) {
var p = new Promise(makeCallWith3SecondLatency);
return stallPromise(p, minDelay);
}
function printResult(result) {
console.log('result: ' + result)
}
var minDelay = 5000;
doSomethingAsync(minDelay).then(printResult);