Path: blob/trunk/third_party/closure/goog/result/result_interface.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 Defines an interface that represents a Result.16*17* NOTE: goog.result is soft deprecated - we expect to replace this and18* {@link goog.async.Deferred} with {@link goog.Promise}.19*/2021goog.provide('goog.result.Result');2223goog.require('goog.Thenable');24252627/**28* A Result object represents a value returned by an asynchronous29* operation at some point in the future (e.g. a network fetch). This is akin30* to a 'Promise' or a 'Future' in other languages and frameworks.31*32* @interface33* @extends {goog.Thenable}34* @deprecated Use {@link goog.Promise} instead - http://go/promisemigration35*/36goog.result.Result = function() {};373839/**40* Attaches handlers to be called when the value of this Result is available.41* Handlers are called in the order they were added by wait.42*43* @param {function(this:T, !goog.result.Result)} handler The function called44* when the value is available. The function is passed the Result object as45* the only argument.46* @param {T=} opt_scope Optional scope for the handler.47* @template T48*/49goog.result.Result.prototype.wait = function(handler, opt_scope) {};505152/**53* The States this object can be in.54*55* @enum {string}56* @deprecated Use {@link goog.Promise} instead - http://go/promisemigration57*/58goog.result.Result.State = {59/** The operation was a success and the value is available. */60SUCCESS: 'success',6162/** The operation resulted in an error. */63ERROR: 'error',6465/** The operation is incomplete and the value is not yet available. */66PENDING: 'pending'67};686970/**71* @return {!goog.result.Result.State} The state of this Result.72*/73goog.result.Result.prototype.getState = function() {};747576/**77* @return {*} The value of this Result. Will return undefined if the Result is78* pending or was an error.79*/80goog.result.Result.prototype.getValue = function() {};818283/**84* @return {*} The error slug for this Result. Will return undefined if the85* Result was a success, the error slug was not set, or if the Result is86* pending.87*/88goog.result.Result.prototype.getError = function() {};899091/**92* Cancels the current Result, invoking the canceler function, if set.93*94* @return {boolean} Whether the Result was canceled.95*/96goog.result.Result.prototype.cancel = function() {};979899/**100* @return {boolean} Whether this Result was canceled.101*/102goog.result.Result.prototype.isCanceled = function() {};103104105106/**107* The value to be passed to the error handlers invoked upon cancellation.108* @constructor109* @extends {Error}110* @final111* @deprecated Use {@link goog.Promise} instead - http://go/promisemigration112*/113goog.result.Result.CancelError = function() {114// Note that this does not derive from goog.debug.Error in order to prevent115// stack trace capture and reduce the amount of garbage generated during a116// cancel() operation.117};118goog.inherits(goog.result.Result.CancelError, Error);119120121