i have some server-side code for deleting a user that looks something like this (assume it’s being called from a Meteor.method() where i’ve already done all the security checks):
i’m ok w/ the comments and posts deletion code run “at the same time”, but i don’t want to delete the actual user account until both those complete. currently, i have no promises or async implemented, but i would like to.
i’m most familiar w/ the $q library, and i see there is a Meteor package for it. but given what’s available in Meteor 1.3, ES6, and coming in ES7, what would be best practice right now?
A good Meteor way to go about this is with the collection hooks - a perfect use case is removing documents related to a deleted user account. No need to worry about promises in your situation.
thanks, @habitatmike, that is an excellent solution to my stated problem. and i’ll probably incorporate that into my solution.
as it turns out, i’ve over-simplified my issue. in reality, i have several more (non-user) collections to clean up, and some of those should not start until a previous one has finished.
in order to coordinate those, is it Promises i want to use, vs say some other async method? if so, is there a promises library that is popular in the community?
@zimv20 Using promises would be the most straight-forward approach, as it is designed for situations like the one you are explaining + no dependencies!
If these functions are run inside a method on the server they will run sequentially. Meteor’s non-callback Mongo methods run inside fibers and execution proceeds only when the preceding operation is complete.
@robfallows, you are right given my over-simplified examples. in the actual app, some of the remove()'s do have callbacks, and i need to coordinate among those.