2.7.0-beta • Published 5 months ago

vait v2.7.0-beta

Weekly downloads
2
License
MIT
Repository
github
Last release
5 months ago

异步编程的一些实用函数。


安装

yarn add vait
# or
npm install --save vait

示例

import { timeout } from 'vait'

timeout(1000).then(() => {
  console.log('hello after 1000ms')
})
import { Serial, timeout } from 'vait'

const serial = Serial()

function randomNumber(range) {
  Math.floor(Math.random() * range);
}

serial(async () => {
  await timeout(randomNumber(100))
  console.log('step one')
})
serial(async () => {
  await timeout(randomNumber(100))
  console.log('step two')
})
serial(async () => {
  await timeout(randomNumber(100))
  console.log('step three')
})

// 永远按调用顺序输出:
//   step one
//   step two
//   step three
import { Wait } from 'vait'

const [wait, go] = Wait()

wait.then(str => {
  // 如果不执行 go, 此函数将永远不会执行
  console.log(str)
})

go('hello, world') // 支持一个参数传入

go() // 因为是调用了 Promise resolve,所以前面 console.log(str) 只会执行一次
// 一个"卡"住运行时的用法
import { Wait } from 'vait'

const [wait, go] = Wait()

;(async () => {
  const value = await wait
  console.log('value accepted:', value)
})()

setTimeout(() => {
  // 一秒后才会出现 value accepted: 3.1415926
  go(3.1415926)
}, 1000)
2.7.0-beta

5 months ago

2.6.0

5 months ago

2.5.2

5 months ago

2.0.3

2 years ago

2.0.2

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.5.1

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago