fix: the API of es6-promisify is not the same as promisify-es6 (#905)

This commit is contained in:
Alex Potsides
2021-03-26 17:13:07 +00:00
committed by GitHub
parent c3e147df6b
commit a7128f07ec
3 changed files with 72 additions and 9 deletions

View File

@ -2,7 +2,7 @@
const NatAPI = require('@motrix/nat-api')
const debug = require('debug')
const promisify = require('es6-promisify')
const { promisify } = require('es6-promisify')
const Multiaddr = require('multiaddr')
const log = Object.assign(debug('libp2p:nat'), {
error: debug('libp2p:nat:err')
@ -132,14 +132,32 @@ class NatManager {
}
const client = new NatAPI(this._options)
const map = promisify(client.map, { context: client })
const destroy = promisify(client.destroy, { context: client })
const externalIp = promisify(client.externalIp, { context: client })
/** @type {(...any) => any} */
const map = promisify(client.map.bind(client))
/** @type {(...any) => any} */
const destroy = promisify(client.destroy.bind(client))
/** @type {(...any) => any} */
const externalIp = promisify(client.externalIp.bind(client))
// these are all network operations so add a retry
this._client = {
// these are all network operations so add a retry
/**
* @param {...any} args
* @returns {Promise<void>}
*/
map: (...args) => retry(() => map(...args), { onFailedAttempt: log.error, unref: true }),
/**
* @param {...any} args
* @returns {Promise<void>}
*/
destroy: (...args) => retry(() => destroy(...args), { onFailedAttempt: log.error, unref: true }),
/**
* @param {...any} args
* @returns {Promise<string>}
*/
externalIp: (...args) => retry(() => externalIp(...args), { onFailedAttempt: log.error, unref: true })
}