There's more...

Adding asynchronous network behaviors to our application can also create unexpected side-effects in our application's behavior. One of the most common issues is dealing with concurrency, or what happens when multiple events are happening simultaneously.

One unexpected behavior of our BlogPosts Service's getNextPage method is that it could be clicked many times by a user before the first click finally resolves its HTTP request. These duplicate requests are a waste of network resources and would actually cause a bug, whereby duplicates of blog posts could be appended to our posts list.

A simple solution to this problem is to prevent multiple calls to our service by having our loadMorePosts event manage its own asynchronous state: ...

Get MEAN Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.