Path: blob/trunk/third_party/closure/goog/result/deferredadaptor.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview An adaptor from a Result to a Deferred.16*17* TODO (vbhasin): cancel() support.18* TODO (vbhasin): See if we can make this a static.19* TODO (gboyer, vbhasin): Rename to "Adapter" once this graduates; this is the20* proper programmer spelling.21*/222324goog.provide('goog.result.DeferredAdaptor');2526goog.require('goog.async.Deferred');27goog.require('goog.result');28goog.require('goog.result.Result');29303132/**33* An adaptor from Result to a Deferred, for use with existing Deferred chains.34*35* @param {!goog.result.Result} result A result.36* @constructor37* @extends {goog.async.Deferred}38* @final39* @deprecated Use {@link goog.Promise} instead - http://go/promisemigration40*/41goog.result.DeferredAdaptor = function(result) {42goog.result.DeferredAdaptor.base(this, 'constructor');43goog.result.wait(result, function(result) {44if (this.hasFired()) {45return;46}47if (result.getState() == goog.result.Result.State.SUCCESS) {48this.callback(result.getValue());49} else if (result.getState() == goog.result.Result.State.ERROR) {50if (result.getError() instanceof goog.result.Result.CancelError) {51this.cancel();52} else {53this.errback(result.getError());54}55}56}, this);57};58goog.inherits(goog.result.DeferredAdaptor, goog.async.Deferred);596061