-
-
Save veeramarni/be578ec907723b13899e to your computer and use it in GitHub Desktop.
Async call from within a Meteor server side method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Meteor.isServer) { | |
var Fiber = Npm.require('fibers'); | |
function async (cb) { | |
Meteor.setTimeout(function () { | |
cb(null, 'hello'); | |
}, 3000); | |
} | |
Meteor.methods({ | |
callAsync: function () { | |
var fiber = Fiber.current; | |
var fence = Meteor._CurrentWriteFence.get() | |
, handle = fence && fence.beginWrite(); | |
async(function (err, res) { | |
handle && handle.committed(); | |
fiber.run(res); | |
}); | |
return Fiber.yield(); | |
} | |
}); | |
} | |
if (Meteor.isClient) { | |
testCallAsync = function () { | |
Meteor.call('callAsync', function (err, res) { | |
if (err) console.log(err); | |
else console.log('response: ', res); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment