Skip to content

Instantly share code, notes, and snippets.

@lozadaOmr
Created October 12, 2018 03:03
Show Gist options
  • Save lozadaOmr/79c39213cb7bb913fda22f9a16641aaa to your computer and use it in GitHub Desktop.
Save lozadaOmr/79c39213cb7bb913fda22f9a16641aaa to your computer and use it in GitHub Desktop.
new Promise resolve()
'use strict'
global.Promise = require('bluebird')
let countStream = function () {
console.log('counting streams..')
return Promise.resolve(Math.floor(Math.random() * 2))
}
let countInvSync = function () {
console.log('counting inv syncs..')
return Promise.resolve(Math.floor(Math.random() * 2))
}
let fnB = function () {
return new Promise(resolve => {
countStream().then(strmCount => {
console.log('stream count:', strmCount)
if (strmCount === 0) return resolve()
return Promise.resolve()
}).then(() => {
return countInvSync().then(syncCount => {
console.log('invSync count:', syncCount)
if (syncCount === 0) return resolve()
return Promise.resolve()
})
}).then(() => {
console.log('doing core stuff here..')
return resolve()
})
})
}
fnB().then(() => {
console.log('function fnB() done!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment