handle(response) {
    if (response instanceof Promise) {
      // Async mode: invoke the callback with the result of the promise.
      if (this.callback) {
        const callback = (result, error=undefined) => {
          try {
            return this.callback(result, /** @type {string} */ (error));
          } catch (callbackError) {
            setTimeout(() => {  // Do the throw outside the Promise handlers.
              throw callbackError;
            }, 0);
          }
        };
        response.then(callback, (error) => callback(undefined, error));
      }
      // We should not be running in async mode without a callback, but it is
      // still useful to return the promise.
    } else {
      // Sync mode: convert the fake "instant" promise to actual result.
      response.then((result) => { response = result; });
    }
    return response;
  }
Wraps a promise returned by an API call, to call the configured callback.
Also handles the "fake promise" returned in synchronous mode.

@template T
@param {!Promise<T>} response
@return {!T|!Promise<T>} Immediate value in sync mode (constructor called
  without callback), and otherwise a promise which will resolve to the
  value.