trek/pretender — pull request #48 by DingoEatingFuzz (2014-12-27 00:36:13+00:00)
Title: Async Responses

PR for issue https://github.com/trek/pretender/issues/41

- Makes responses asynchronous by default
- Responses resolve on the next run of the event loop by default
- Responses can be made synchronous by passing `false` for the async argument when specifying a route
```js
pretender.get('/sync/thing', handlerFn, false)
```
- Responses can be set to resolve after a specified time by passing in a number for the async argument
```js
pretender.get('/timed/thing', handlerFn, 300) // in ms just like setTimeout
```
- Responses can be set to never automatically resolve by passing in `true` for the async argument
```js
pretender.get('/manual/thing', handlerFn, true);
// ...
pretender.resolve('/manual/thing');
```
- Responses can be set to conditionally resolve by passing in a function for the async argument
```js
pretender.get('/maybe/async/thing', handlerFn, function() { return isAsync ? 0 : false; })
```
- A helper by the name of `pretender.requiresManualResolution` exists to check if a request will, well, require manual resolution.