mercredi 17 juin 2015

Publisher in Pub/Sub should be Synchronous or Asynchronous?

My view on mechanism:

  • Pattern wise publisher should just publish an event and should not care about listeners / subscribers for that topic / event.
  • In case of JavaScript, lot of frameworks for Pub / Sub publishes event in Sync manner
  • for example : framework just maintains map of event to function.
  • on particular event occurrence, it iterates over subscribers and calls function one by one - > function_1.apply(context, args) and then function_2.apply(context, args)
  • This makes it Synchronous as, unless and until function_1 finishes, function_2 is unaware that particular event happened.

What is an ideal way of implementing Pub / Sub in JavaScript ?

Aucun commentaire:

Enregistrer un commentaire