@sagacious/sync
v0.0.3
Published
synchronous promise or function that returns promise
Downloads
2
Maintainers
Readme
🐎 sync
synchronous promise or function that returns promise
Inspired by synchronized-promise and promise-synchronizer
example
const sync = require('@sagacious/sync')
/**
* sync.fun
*/
async function say () {
const res = await new Promise(r => {
setTimeout(() => {
r('hello')
}, 1000)
})
return res
}
const syncSay = sync.fun(say)
say() // asynchronous execution, return promise
syncSay() // synchronous execution, return 'hello'
/**
* sync.p
*/
sync.p(new Promise(r => {
setTimeout(() => {
r('hello')
}, 1000)
})) // first echo 'hello'
console.log('world') // and then echo 'world'