4.2.1 • Published 1 year ago

vait v4.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

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


安装

yarn add vait
# or
npm install --save vait

示例

import { timeout } from 'vait'

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

const sq = Sequence()

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

sq(async () => {
  await timeout(randomNumber(100))
  console.log('step one')
})
sq(async () => {
  await timeout(randomNumber(100))
  console.log('step two')
})
sq(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 [waiting, go] = Wait()

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

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

1 year ago

3.4.4

1 year ago

3.4.3

1 year ago

3.4.2

1 year ago

3.4.1

1 year ago

4.1.0

1 year ago

4.0.0

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

2.7.0-beta

2 years ago

2.6.0

2 years ago

2.5.2

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.5.0

3 years ago

2.4.0

3 years ago

2.5.1

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago