postaljs / postal.js

JavaScript pub/sub library supporting advanced subscription features, and several helpful add-ons.

Home Page:http://ifandelse.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

allow timeout to be configurable

SoundLogic opened this issue · comments

running into issues using postal.js with Angular - it seems some of these may be, in part, related to the use of setTimeout - it would be helpful if I could provide a timeout function to override the default

I add a PR if agreed

@SoundLogic If I remember correctly, the only usage of setTimeout is in the delay method on the SubscriptionDefinition prototype. Are you asking to be able to use a different function than setTimeout itself? I'm not necessarily opposed, but would like to understand a bit more about why it's a problem with Angular before I make any changes. What sort of issues are you running into (bear in mind I'm not an Angular user, so details will help fill in the gaps for me), and if you were to replace setTimeout, what would you replace it with? FWIW, the SubscriptionDefinition is exposed on the postal namespace, so you could monkey-patch the delay method with your own implementation using whatever option you prefer in place of setTimeout to verify if that would indeed solve your issue.

So this wasn't actually causing a problem for me, I was mistaken. The issue with setTimeout is that it operates outside of the $digest cycle, but the issue I was running into appears to have been related to a $scope inheritance issue related to nested views in ui-router. Either way, I should have realized this wasn't the issue in the first place since I'm using postal.request-response which is configured to use angular's $q and should therefore wrap everything in an angular-safe deferred object. Sorry for the confusion. Closing the ticket..