I have the following code in Meteor (nodejs framework)
dbAllSync = Meteor._wrapAsync(db.all.bind(db))
rows = dbAllSync(query)
With the above code I am able to fully block the db call i.e. the code execution will only continue to the line after when the query results have been fetched.
How can I achieve the same full block code execution in nodejs without using Meteor._wrapAsync?
P.s. - I have tried 'sync' and 'synchronise' node packages. It didn't server my purpose. They don't have full-block code execution but non-blocking code execution.
Also, I know full-block is against the nodejs principle. But I have some requirements to implement and for that I want nodejs to be full-block at some points in code.
Thanks in advance.
Under the hood, Meteor.wrapAsync is a wrapper around the fibers/future library.
https://github.com/laverdet/node-fibers
The fibers mechanism doesn't full-block the node event loop, the whole process kepts executing stuff in a non-blocking asynchronous way, it just appears synchronous to the developer.
This is very different from the fs functions like writeSync that are truly blocking the process.
EDIT : adding some boilerplate code :
var Future=require("fibers/future");
var future=new Future();
api.someAsyncFunc(params,future.resolver());
future.wait();
You can dig in the docs of the node-fibers npm module to find more about nice wrapping functionalities like Future.wrap.