jack e1a2621c78 update | 2 years ago | |
---|---|---|
.. | ||
es2015 | 2 years ago | |
source | 2 years ago | |
.npmignore | 2 years ago | |
HISTORY.md | 2 years ago | |
LICENSE.md | 2 years ago | |
README.md | 2 years ago | |
index.js | 2 years ago | |
package.json | 2 years ago |
Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).
npm install --save ambi
require('ambi')
npm install --save ambi
require('ambi')
//wzrd.in/bundle/ambi@2.5.0
ender add ambi
require('ambi')
This package is published with the following editions:
ambi
aliases ambi/index.js
which uses Editions to automatically select the correct edition for the consumers environmentambi/source/index.js
is Source + ESNext + Requireambi/es2015/index.js
is Babel Compiled + ES2015 + RequireOlder environments may need Babel's Polyfill or something similar.
// Import
const ambi = require('ambi')
let result = null
// Sample methods
function syncMethod (x, y) {
return x * y
}
function asyncMethod (x, y, next) {
return setTimeout(function () {
next(null, x * y)
}, 0)
}
// Call the synchronous function asynchronously
// ambi adds support for this asynchronous callback automatically
result = ambi(syncMethod, 5, 2, function(err, result) {
console.log(err, result) // null, 10
})
console.log(result) // 10 - just like normal
// Call the asynchronous function asynchronously
// ambi doesn't do anything special here
result = ambi(asyncMethod, 5, 2, function (err, result) {
console.log(err, result) // null, 10
})
console.log(result) // setTimeout - just like normal
(method, ...args)
method
is the function to execute...args
is the arguments to send to the method
(err, ...results)
err
argumenterr
argument equal to null, and a result
argument equal to the returned result of the synchronous method[methodToFire, methodToIntrospect]
as the method
argumentDiscover the release history by heading on over to the HISTORY.md
file.
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
These amazing people are maintaining this project:
No sponsors yet! Will you be the first?
These amazing people have contributed code to this project:
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
Unless stated otherwise all works are:
and licensed under: