run-async
Run Async
Utility method to run a function either synchronously or asynchronously using a series of common patterns. This is useful for library author accepting sync or async functions as parameter. runAsync
will always run them as an async method, and normalize the multiple signature.
Installation
Usage
Here's a simple example print the function results and three options a user can provide a function.
Using this.async
Returning a promise
Synchronous function
runAsync.cb
runAsync.cb
supports all the function types that runAsync
does and additionally a traditional callback as the last argument signature:
If your version of node support Promises natively (node >= 0.12), runAsync
will return a promise. Example: runAsync(func)(arg1, arg2).then(cb)
Licence
Copyright (c) 2014 Simon Boudrias (twitter: @vaxilart) Licensed under the MIT license.
Last updated