0.1.9 • Published 3 years ago

@x_m/utils v0.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@x_m/utils

一些常用功能函数

install

yarn add @x_m/utils

examples

genePromiseOnce
sleepMs


genePromiseOnce

// expensiveButStorableAsyncFunction will be called only once forever, unless rejected
const promiseOnce = genePromiseOnce(expensiveButStorableAsyncFunction)

window.addEventListener('resize', () => {
  promiseOnce()
    .then((res) => {
      console.log(`promise successed: ${res}`)
    })
    .catch(() => {
      console.log('catch')
    })
})

↑ examples ↑

sleepMs

async function() {
  await sleepMs(500)
}

↑ examples ↑