Synchron
Wrapping an async function into a synchron function call without blocking.
Install
npm install synchron --save
Using Synchron
Create a new instance of Synchro and use the methods return
and throw
. The wait
method will wait until
return
or throw
was called.
const Synchron = ; var asyncTimeout = ; ; // non-blocking wait until done was calledasyncTimeout;console; // output:// -------// inside setTimeout// back in main
Create a new instance and pass a function to wrap the asnyc call into a synchron function.
The warpped function will run in the context of Synchron
, so you can use this.return
and/or this.throw
.
If you like to exit the async function without returning a result just call this.return()
without a parameter or call this.done()
.
const Synchron = ; var readFileSync = { var fs = ; fs;}; try // here is the synchron function call var data = ; console; catch err // if an error occours the function will throw it and you can catch it console; // maybe an error like: "ENOENT: no such file or directory, open './testfile.txt'"