https://github.com/zenflow/p-call
Call a legacy async method and return a promise
https://github.com/zenflow/p-call
Last synced: about 1 year ago
JSON representation
Call a legacy async method and return a promise
- Host: GitHub
- URL: https://github.com/zenflow/p-call
- Owner: zenflow
- Created: 2017-12-15T22:47:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-15T16:34:00.000Z (over 8 years ago)
- Last Synced: 2024-04-14T18:37:28.448Z (about 2 years ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# p-call
Call a legacy async method and return a promise
Very similar to [promisify-call](https://github.com/bojand/promisify-call) but always promisifies the call, rather than guessing if it should.
---
### Example
Instead of using the legacy error-first callback API ...
```js
object.method(argument, (error, result) => {
if (error) {
throw error
}
console.log(result)
})
```
Use the Promise API ...
```js
const result = await pCall(object, object.method, argument)
console.log(result)
// Or, specify the function as a property key of `object`...
const result = await pCall(object, 'method', argument)
console.log(result)
```