0.0.3 • Published 4 years ago

@sagacious/sync v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

🐎 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'