WhisperSystems/Signal-iOS — pull request #127 by Strilanc (2014-08-20 23:57:56+00:00)
Title: Using an external futures library instead of custom futures

Please do manual testing before merging this change. It's rather large, and I don't own an iphone to make sure more than just the tests pass. Also, another pair of eyes double-checking the huge number of small changes would be good.

Basically I had previously derived Collapsing Futures from Signal's futures, so they were semantically very close. The main difference is that collapsing futures doesn't catch exceptions, it automatically runs callbacks on the main thread when they're registered from the main thread, and its FutureSource has-a Future instead of is-a Future.

- I added `thenTry`, `catchTry`, and `finallyTry` category methods to perform continuations that catch and wrap exceptions. All continuations in Signal are now done with those methods, unless I was sure it was safe to do otherwise.
- Added `operationTry`, which wraps a future-returning canceltoken-taking method to catch and wrap exceptions propagating out of it.
- Moved methods not in Collapsing Futures into FutureUtil. Basically that's just `asyncTry`, which I renamed to `retry`.
- I removed Future/CancelToken/TimeoutFailure and other classes from Signal.
- The async directory was just two classes, so removed it and moved FutureUtil and ObservableValue to Util.

As a side effect of making these changes I also:
- Added an environment flag to the unit test target, and a branch in the app startup to abort when it's detected. Avoids the phone number directory being downloaded (if out of date) when unit tests start, and other not-appropriate-during-tests stuff.
- As a side effect of the above change, the Environment is null unless tests initialize it. This caused a few failures for tests trying to grab the logger. I modified the logger to return nil when the environment wasn't initialized.
- The 'churn until' test macro now allows callbacks scheduled to run on the main run loop to run.

Potential side effects or regressions:
- There is no longer verbose logging when a failed future is constructed.
- There is probably a typo introduced *somewhere*, although I've checked things over twice.

FREEBIE