async-event2

0.0.3 • Public • Published

example

const AsyncEvent = require('./index')

const asyncEvent = new AsyncEvent({ onStart: () => { console.log('执行前函数') },

  onEnd: () => {
      console.log(('执行完函数'))
  },

  onErr: () => {
      console.log('上一个函数未运行完,已被拦截')
  }

}, 10000)

const fun = function (done) { console.log('运行主体') // 模拟ajax执行延时 setTimeout(() => { console.log('模拟ajax') done() }, 2000) }

asyncEvent.run(fun) // 正常运行 asyncEvent.run(fun) // 被拦截

setTimeout(() => { asyncEvent.run((done) => { console.log('第二允许成功') done() }) }, 5000) // 正常应允许成功

Readme

Keywords

Package Sidebar

Install

npm i async-event2

Weekly Downloads

1

Version

0.0.3

License

ISC

Unpacked Size

2.99 kB

Total Files

4

Last publish

Collaborators

  • jzyong