OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 */ | 1415 */ |
1416 callWhenDone: function(callback) | 1416 callWhenDone: function(callback) |
1417 { | 1417 { |
1418 console.assert(!this._outgoingCallback, "CallbackBarrier.callWhenDone()
is called multiple times"); | 1418 console.assert(!this._outgoingCallback, "CallbackBarrier.callWhenDone()
is called multiple times"); |
1419 this._outgoingCallback = callback; | 1419 this._outgoingCallback = callback; |
1420 if (!this._pendingIncomingCallbacksCount) | 1420 if (!this._pendingIncomingCallbacksCount) |
1421 this._outgoingCallback(); | 1421 this._outgoingCallback(); |
1422 }, | 1422 }, |
1423 | 1423 |
1424 /** | 1424 /** |
| 1425 * @return {!Promise.<undefined>} |
| 1426 */ |
| 1427 donePromise: function() |
| 1428 { |
| 1429 return new Promise(promiseConstructor.bind(this)); |
| 1430 |
| 1431 /** |
| 1432 * @param {function()} success |
| 1433 * @this {CallbackBarrier} |
| 1434 */ |
| 1435 function promiseConstructor(success) |
| 1436 { |
| 1437 this.callWhenDone(success); |
| 1438 } |
| 1439 }, |
| 1440 |
| 1441 /** |
1425 * @param {function(...)=} userCallback | 1442 * @param {function(...)=} userCallback |
1426 */ | 1443 */ |
1427 _incomingCallback: function(userCallback) | 1444 _incomingCallback: function(userCallback) |
1428 { | 1445 { |
1429 console.assert(this._pendingIncomingCallbacksCount > 0); | 1446 console.assert(this._pendingIncomingCallbacksCount > 0); |
1430 if (userCallback) { | 1447 if (userCallback) { |
1431 var args = Array.prototype.slice.call(arguments, 1); | 1448 var args = Array.prototype.slice.call(arguments, 1); |
1432 userCallback.apply(null, args); | 1449 userCallback.apply(null, args); |
1433 } | 1450 } |
1434 if (!--this._pendingIncomingCallbacksCount && this._outgoingCallback) | 1451 if (!--this._pendingIncomingCallbacksCount && this._outgoingCallback) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 * @param {T} defaultValue | 1489 * @param {T} defaultValue |
1473 * @return {!Promise.<T>} | 1490 * @return {!Promise.<T>} |
1474 * @template T | 1491 * @template T |
1475 */ | 1492 */ |
1476 Promise.prototype.catchException = function(defaultValue) { | 1493 Promise.prototype.catchException = function(defaultValue) { |
1477 return this.catch(function (error) { | 1494 return this.catch(function (error) { |
1478 console.error(error); | 1495 console.error(error); |
1479 return defaultValue; | 1496 return defaultValue; |
1480 }); | 1497 }); |
1481 } | 1498 } |
OLD | NEW |