promisify-event一些笔记

为什么要

01.超级轻量

它是什么

Promisify EventEmitter's event.

如何使用

安装类库

npm install promisify-event

基础架构

// 引入类库
const promisifyEvent = require('promisify-event');

// 一些用法
//2 添加事件监听
//3 示例01
// Promisify server's `listening` event:
promisifyEvent(server, `listening`).then(() => {
  // ...
});
//3 示例02
// Promisify `error` event. `error` event always rejects the promise:
promisifyEvent(server, 'error').catch(() => {
  // ...
});
//3 示例02
// Cancel event subscription and promise (it will be never fulfilled):
let listeningPromise = promisifyEvent(server, `listening`);

//2 移除事件监听
listeningPromise.cancel();
listeningPromise.then(() => {
  // Will never happen
});

参考文献

inikulin.promisify-event npm github

你可能感兴趣的:(promisify-event一些笔记)