sfcode
An Online Competing and Development Environment
|
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.
Here's a simple example print the function results and three options a user can provide a function.
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)
Copyright (c) 2014 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.