Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: ui/webui/resources/js/promise_resolver.js

Issue 1871043004: Make PromiseResolver's members read-only (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: base off of https://codereview.chromium.org/1869883003/ Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/webui/resources/js/compiled_resources2.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 19 /**
20 * @constructor @struct 20 * @constructor @struct
21 * @template T 21 * @template T
22 */ 22 */
23 function PromiseResolver() { 23 function PromiseResolver() {
24 /** @type {function(T): void} */ 24 /** @private {function(T): void} */
25 this.resolve; 25 this.resolve_;
26 26
27 /** @type {function(*=): void} */ 27 /** @private {function(*=): void} */
28 this.reject; 28 this.reject_;
29 29
30 /** @type {!Promise<T>} */ 30 /** @private {!Promise<T>} */
31 this.promise = new Promise(function(resolve, reject) { 31 this.promise_ = new Promise(function(resolve, reject) {
32 this.resolve = resolve; 32 this.resolve_ = resolve;
33 this.reject = reject; 33 this.reject_ = reject;
34 }.bind(this)); 34 }.bind(this));
35 } 35 }
36
37 PromiseResolver.prototype = {
38 /** @return {!Promise<T>} */
39 get promise() { return this.promise_; },
40 set promise(p) { assertNotReached(); },
41
42 /** @return {function(T): void} */
43 get resolve() { return this.resolve_; },
44 set resolve(r) { assertNotReached(); },
45
46 /** @return {function(*=): void} */
47 get reject() { return this.reject_; },
48 set reject(s) { assertNotReached(); },
49 };
OLDNEW
« no previous file with comments | « ui/webui/resources/js/compiled_resources2.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698