Skip to content

🐴 synchronous promise or function that returns promise

Notifications You must be signed in to change notification settings

SagaciousLittle/sagacious-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

🐴 synchronous promise or function that returns promise

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published