Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview PromiseResolver is a helper class that allows creating a | 6 * @fileoverview PromiseResolver is a helper class that allows creating a |
| 7 * Promise that will be fulfilled (resolved or rejected) some time later. | 7 * Promise that will be fulfilled (resolved or rejected) some time later. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * var resolver = new PromiseResolver(); | 10 * var resolver = new PromiseResolver(); |
| 11 * resolver.promise.then(function(result) { | 11 * resolver.promise.then(function(result) { |
| 12 * console.log('resolved with', result); | 12 * console.log('resolved with', result); |
| 13 * }); | 13 * }); |
| 14 * ... | 14 * ... |
| 15 * ... | 15 * ... |
| 16 * resolver.resolve({hello: 'world'}); | 16 * resolver.resolve({hello: 'world'}); |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 /** @constructor */ | 19 /** |
| 20 * @constructor | |
| 21 * @template T | |
| 22 */ | |
| 20 function PromiseResolver() { | 23 function PromiseResolver() { |
| 21 /** @type {!Function} */ | 24 /** @type {function(T): void} */ |
| 22 this.resolve; | 25 this.resolve; |
| 23 | 26 |
| 24 /** @type {!Function} */ | 27 /** @type {function(*=): void} */ |
| 25 this.reject; | 28 this.reject; |
|
Dan Beam
2016/03/04 19:29:26
maybe you already mentioned this (as I remember va
dpapad
2016/03/04 20:01:28
Thanks for asking, this reminded me that I forgot
| |
| 26 | 29 |
| 27 /** @type {!Promise} */ | 30 /** @type {!Promise<T>} */ |
| 28 this.promise = new Promise(function(resolve, reject) { | 31 this.promise = new Promise(function(resolve, reject) { |
| 29 this.resolve = resolve; | 32 this.resolve = resolve; |
| 30 this.reject = reject; | 33 this.reject = reject; |
| 31 }.bind(this)); | 34 }.bind(this)); |
| 32 } | 35 } |
| OLD | NEW |