result_interface.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2012 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Defines an interface that represents a Result.
  16. *
  17. * NOTE: goog.result is soft deprecated - we expect to replace this and
  18. * {@link goog.async.Deferred} with {@link goog.Promise}.
  19. */
  20. goog.provide('goog.result.Result');
  21. goog.require('goog.Thenable');
  22. /**
  23. * A Result object represents a value returned by an asynchronous
  24. * operation at some point in the future (e.g. a network fetch). This is akin
  25. * to a 'Promise' or a 'Future' in other languages and frameworks.
  26. *
  27. * @interface
  28. * @extends {goog.Thenable}
  29. * @deprecated Use {@link goog.Promise} instead - http://go/promisemigration
  30. */
  31. goog.result.Result = function() {};
  32. /**
  33. * Attaches handlers to be called when the value of this Result is available.
  34. * Handlers are called in the order they were added by wait.
  35. *
  36. * @param {function(this:T, !goog.result.Result)} handler The function called
  37. * when the value is available. The function is passed the Result object as
  38. * the only argument.
  39. * @param {T=} opt_scope Optional scope for the handler.
  40. * @template T
  41. */
  42. goog.result.Result.prototype.wait = function(handler, opt_scope) {};
  43. /**
  44. * The States this object can be in.
  45. *
  46. * @enum {string}
  47. * @deprecated Use {@link goog.Promise} instead - http://go/promisemigration
  48. */
  49. goog.result.Result.State = {
  50. /** The operation was a success and the value is available. */
  51. SUCCESS: 'success',
  52. /** The operation resulted in an error. */
  53. ERROR: 'error',
  54. /** The operation is incomplete and the value is not yet available. */
  55. PENDING: 'pending'
  56. };
  57. /**
  58. * @return {!goog.result.Result.State} The state of this Result.
  59. */
  60. goog.result.Result.prototype.getState = function() {};
  61. /**
  62. * @return {*} The value of this Result. Will return undefined if the Result is
  63. * pending or was an error.
  64. */
  65. goog.result.Result.prototype.getValue = function() {};
  66. /**
  67. * @return {*} The error slug for this Result. Will return undefined if the
  68. * Result was a success, the error slug was not set, or if the Result is
  69. * pending.
  70. */
  71. goog.result.Result.prototype.getError = function() {};
  72. /**
  73. * Cancels the current Result, invoking the canceler function, if set.
  74. *
  75. * @return {boolean} Whether the Result was canceled.
  76. */
  77. goog.result.Result.prototype.cancel = function() {};
  78. /**
  79. * @return {boolean} Whether this Result was canceled.
  80. */
  81. goog.result.Result.prototype.isCanceled = function() {};
  82. /**
  83. * The value to be passed to the error handlers invoked upon cancellation.
  84. * @constructor
  85. * @extends {Error}
  86. * @final
  87. * @deprecated Use {@link goog.Promise} instead - http://go/promisemigration
  88. */
  89. goog.result.Result.CancelError = function() {
  90. // Note that this does not derive from goog.debug.Error in order to prevent
  91. // stack trace capture and reduce the amount of garbage generated during a
  92. // cancel() operation.
  93. };
  94. goog.inherits(goog.result.Result.CancelError, Error);