Make InteractionManager.runAfterInteractions() return a Promise

Summary: In accordance with the unwritten rule that any API that takes a callback should also return a promise, I've changed `InteractionManager.runAfterInteractions()` to do just that.

```js
  InteractionManager.runAfterInteractions(() => {
    ...
  });
```
can become
```js
  InteractionManager.runAfterInteractions().then(() => {
    ...
  });
```
(but doesn't have to). Most importantly, though, this change enables code like
```js
  doSomeUIStuff();
  await InteractionManager.runAfterInteractions();
  doSomeNonUIStuff();
```
which is nice.

Note: Because returning a `Promise` means the callback argument is now optional, the behaviour of the API is slightly changed, though not in a backwards-incompatible way (unless a consumer is in some way relying on the exception, but that would be insane).
Closes https://github.com/facebook/react-native/pull/3788

Reviewed By: vjeux

Differential Revision: D2634693

Pulled By: josephsavona

fb-gh-sync-id: 7315120963be23cf69d777e940b2750d32ae47a8
This commit is contained in:
Philipp von Weitershausen 2015-11-09 20:13:27 -08:00 committed by facebook-github-bot-5
parent 6f57766d21
commit d7c8b4478b
1 changed files with 8 additions and 7 deletions

View File

@ -73,13 +73,14 @@ var InteractionManager = {
/** /**
* Schedule a function to run after all interactions have completed. * Schedule a function to run after all interactions have completed.
*/ */
runAfterInteractions(callback: Function) { runAfterInteractions(callback: ?Function): Promise {
invariant( return new Promise(resolve => {
typeof callback === 'function', scheduleUpdate();
'Must specify a function to schedule.' if (callback) {
); _queue.push(callback);
scheduleUpdate(); }
_queue.push(callback); _queue.push(resolve);
});
}, },
/** /**