1.0.1 • Published 1 year ago

@flycran/async-lib v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

介绍

该包用于创建异步事件侦听器,主要作用在我的需要用到异步事件的其他包中作为事件引擎

API

AsyncEvent

异步事件引擎

构造器

new AsyncEvent()

  • 没有参数

方法

  • on

    添加侦听器

    on(type: string, listener: Function): void

    • type

      事件类型

    • listener

      事件侦听器函数

  • off

    移除侦听器,返回值表示是否移除成功

    off(type: string, listener: Function): boolean

    • type

      事件类型

    • listener

      事件侦听器函数

  • emit

    触发事件

    emit(type: string, ...events: any[]): void

AsyncErgodic

异步遍历,同时支持arraysetmapobject,内部使用Promise.all()来并行执行,提高效率,返回值是所有回调返回值的数组

  • data

    数据,可以是arraysetmapobject

  • callBack

    回调函数,参数类似forEach,对于对象,将键名替代索引