Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
921 stars 168 forks source link

Consider promise or callback for db operation complete. #201

Closed myexampleusername closed 5 years ago

myexampleusername commented 8 years ago

There's times when updating a user's role will merit a redirect given new permissions, but without a promise or callback for write operations on updating roles, it's difficult to know when the role has been written to the db such that a router can appropriately route!

Added a promise or callback to your API shouldn't break backwards compatibility.

Thanks!

mitar commented 8 years ago

In 2.0 you should just use functions inside the Meteor method. When the Meteor method returns, you know that it finished.

mitar commented 8 years ago

Calling API methods outside of Meteor methods is discouraged for this and many other reasons.

myexampleusername commented 8 years ago

@mitar I'm actually not calling API methods outside of Meteor methods. Can you show a code example of what you're talking about, 2 comments above? Thanks!

mitar commented 8 years ago

Then you have a callback for your Meteor method, no? You can use that to know when method finished?

Inside Meteor methods calls to roles API behave like synchronous calls.

myexampleusername commented 8 years ago

Ahh, no, that doesn't work. Why don't you show me a working example?

mitar commented 8 years ago

I think it is on you to show me what doesn't work. :-) I sadly do not have time to create examples for you.

myexampleusername commented 8 years ago

Are you French? Just wondering...

mitar commented 8 years ago

No, why?

jsamr commented 8 years ago

I think a callback would guaranty that the write operation has been done on the server mongodb, but not that it has propagated to the client minimongo...

mitar commented 8 years ago

If you have a Meteor method on both client and server side, then on the client side callback is returned when simulation finished, and not when server finishes, so that user gets immediate feedback (latency compensation). If server then fails, client is reverted. If you want this not to happen, define your method only on the server.