Open AlexFrazer opened 8 years ago
It seems that even if you put a try block Restivus returns immediately
Having this challenge as well, tried with Meteor.wrapAsync
too
Any example how to use Meteor.wrapAsync
with restivus?
Need this feature too!
I'm using meteorhacks:async
to turn async code into synchronous code.
I've written a small function on top of it that transforms a promise into synchronous code :
// SyncPromise.js
const { Async } = global
export default promise => {
const { result, error } = Async.runSync(done =>
Promise.resolve(promise).then(
success => done(null, success),
error => {
done(error)
}
)
)
if (error) {
throw error
} else {
return result
}
}
Then you can use as such :
import SyncPromise from "path/to/SyncPromise"
async function action() {
// return await stuffYouWantToReturnAsynchronously()
}
Api.addRoute(
"route",
{},
{
get: {
action() {
return SyncPromise(action())
},
},
}
)
I want to have a route like this:
Just immediately returns the status of the promise.