All posts by Steven Wexler

About Steven Wexler

I’m a software engineer living in Washington D.C. and working at a startup called Hurdlr. I primarily develop in C#, Javascript, and SQL. And I play around with Python and Scala on the side. I enjoy participating as an active member on StackOverflow and working on side projects. Check out my exceptions.js framework!

$q.allSettled – Q.allSettled for angular promises

Q has Q.allSettled. $q does not. The main difference between $q.all and $q.allSettled is that $q.allSettled waits for all promises to resolve or reject (i.e. “settle”). Then it resolves. $q.all rejects when the first project is rejected.

Paraphrased from Q’s documentation:

$q.allSettled returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected.

This method is often used in order to execute a number of operations concurrently and be notified when they all finish, regardless of success or failure.

I’ve noticed a lot of Angular devs request $q.allSettled. So here it is! JS Fiddle.

Continue reading $q.allSettled – Q.allSettled for angular promises

$q.serial – execute promises serially in AngularJS.

Hey AngularJS devs! Let’s talk about executing async tasks serially with promises and how $q.serial can help.

First, we notice .then allows our success/fail callbacks to return a promise. $q treats success/fail callbacks that return promises specially. We’ll look at two examples to see how $q treats success/fail functions that return promises differently from those that don’t.
Continue reading $q.serial – execute promises serially in AngularJS.

Promises and the danger of angular.noop

Recently I started working with AngularJS. One of things I enjoy most about AngularJS are promises. Promises are a design pattern / module useful for asynchronous tasks. Normally, I rave about how awesome promises are, but instead of raving I wanted to talk about something that tripped me up when I first started using promises.

The following promises are not equivalent. And I’m going to explain why.

var deferred = $q.defer();
deferred.promise.then(mySuccessCallback, angular.noop, myNotifyCallback);
deferred.promise.then(mySuccessCallback, null, myNotifyCallback);

Continue reading Promises and the danger of angular.noop

Cached asset files

Recent I’ve been working on a side project Battle States. It’s a simple game modeled off of Mr. Scocus’ (my 6th grade Social Studies teacher) competition that helped us learn state/country names and capitals. I can name all 50 state capitals thanks to him! The backened is powered by django, but most of the logic is written in Javascript. I noticed while developing and in production that often my browser was too aggresively using cached asset files rather than pulling updated assets from my server. This problem was particularly concerning because so much of the logic is written in Javascript.

Continue reading Cached asset files