Skip to content

Commit

Permalink
Remove goog.Promise dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DreierF committed Aug 27, 2020
1 parent 9528b73 commit edcec22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
15 changes: 2 additions & 13 deletions closure/goog/async/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ goog.require('goog.async.throwException');
* assuming either the native, or polyfill version will be used. Does still
* permit tests to use forceNextTick.
*/
goog.ASSUME_NATIVE_PROMISE = goog.define('goog.ASSUME_NATIVE_PROMISE', false);
goog.ASSUME_NATIVE_PROMISE = true;

/**
* Fires the provided callback just before the current callstack unwinds, or as
Expand Down Expand Up @@ -52,21 +52,10 @@ goog.async.run = function(callback, opt_context) {
* @private
*/
goog.async.run.initializeRunner_ = function() {
if (goog.ASSUME_NATIVE_PROMISE ||
(goog.global.Promise && goog.global.Promise.resolve)) {
// Use goog.global.Promise instead of just Promise because the relevant
// externs may be missing, and don't alias it because this could confuse the
// compiler into thinking the polyfill is required when it should be treated
// as optional.
var promise = goog.global.Promise.resolve(undefined);
var promise = Promise.resolve(undefined);
goog.async.run.schedule_ = function() {
promise.then(goog.async.run.processWorkQueue);
};
} else {
goog.async.run.schedule_ = function() {
goog.async.nextTick(goog.async.run.processWorkQueue);
};
}
};


Expand Down
10 changes: 4 additions & 6 deletions closure/goog/timer/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

goog.provide('goog.Timer');

goog.require('goog.Promise');
goog.require('goog.events.EventTarget');


Expand Down Expand Up @@ -301,23 +300,22 @@ goog.Timer.clear = function(timerId) {

/**
* @param {number} delay Milliseconds to wait.
* @param {(RESULT|goog.Thenable<RESULT>|Thenable)=} opt_result The value
* @param {(RESULT|Thenable)=} opt_result The value
* with which the promise will be resolved.
* @return {!goog.Promise<RESULT>} A promise that will be resolved after
* @return {!Promise<RESULT>} A promise that will be resolved after
* the specified delay, unless it is canceled first.
* @template RESULT
*/
goog.Timer.promise = function(delay, opt_result) {
var timerKey = null;
return new goog
.Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
timerKey =
goog.Timer.callOnce(function() { resolve(opt_result); }, delay);
if (timerKey == goog.Timer.INVALID_TIMEOUT_ID_) {
reject(new Error('Failed to schedule timer.'));
}
})
.thenCatch(function(error) {
.catch(function(error) {
// Clear the timer. The most likely reason is "cancel" signal.
goog.Timer.clear(timerKey);
throw error;
Expand Down

0 comments on commit edcec22

Please sign in to comment.