node-fibers

How to wrap async function calls into a sync function in Node.js or Javascript?

纵然是瞬间 提交于 2019-11-26 08:51:27
问题 Suppose you maintain a library that exposes a function getData . Your users call it to get actual data: var output = getData(); Under the hood data is saved in a file so you implemented getData using Node.js built-in fs.readFileSync . It\'s obvious both getData and fs.readFileSync are sync functions. One day you were told to switch the underlying data source to a repo such as MongoDB which can only be accessed asynchronously. You were also told to avoid pissing off your users, getData API

“Meteor code must always run within a Fiber” when calling Collection.insert on server

試著忘記壹切 提交于 2019-11-26 07:29:40
问题 I have the following code in server/statusboard.js; var require = __meteor_bootstrap__.require, request = require(\"request\") function getServices(services) { services = []; request(\'http://some-server/vshell/index.php?type=services&mode=json\', function (error, response, body) { var resJSON = JSON.parse(body); _.each(resJSON, function(data) { var host = data[\"host_name\"]; var service = data[\"service_description\"]; var hardState = data[\"last_hard_state\"]; var currState = data[\