Prevent adding a gateway twice

Prevent adding an existing gateway.

The first three commits belong to #695 and #697, and should disappear once they get merged.

Fixes #692.
@nullstyle is already working on this. I actually tried a slightly different abstraction, noticed it actually bloated the line count overall, and undid the changes. I think Scott is abstracting it similar to the way you describe.

I actually implemented ```$q.allSettled()```, for this https://github.com/angular/angular.js/pull/8738.