JSFiddle - React, Tailwind, and code Playground
by dumptyd
JavaScript
const DPromise = function(func, pp) {
this.thenPromise = undefined;
func && func(this.resolve.bind(this));
};
DPromise.prototype.resolve = function() {
this.thenFunc && this.thenFunc(...arguments);
return this;
};
DPromise.prototype.then = function(func) {
return new DPromise();
};
const p = new DPromise(function(resolve) {
console.log('timeout started');
setTimeout(() => resolve('timeout completed'), 3000);
}).then(function(timeoutMsg) {
console.log('pdata', timeoutMsg);
}).then(function(m) {
console.log('Something that runs after everything', m);
});
(function() {
console.log('timeout started');
setTimeout(() => {
console.log('timeout completed');
console.log('second timeout started');
setTimeout(() => {
console.log('second timeout completed');
console.log('third timeout started');
setTimeout(() => {
console.log('third timeout completed');
}, 1000)
}, 1000);
}, 1000);
});