Source: externs/shaka/abortable.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @externs
  8. */
  9. /**
  10. * A representation of an abortable operation. Note that these are not
  11. * cancelable. Cancellation implies undoing what has been done so far,
  12. * whereas aborting only means that further work is stopped.
  13. *
  14. * @interface
  15. * @template T
  16. * @exportDoc
  17. */
  18. shaka.extern.IAbortableOperation = class {
  19. constructor() {
  20. /**
  21. * A Promise which represents the underlying operation. It is resolved when
  22. * the operation is complete, and rejected if the operation fails or is
  23. * aborted. Aborted operations should be rejected with a shaka.util.Error
  24. * object using the error code OPERATION_ABORTED.
  25. *
  26. * @const {!Promise<T>}
  27. * @exportDoc
  28. */
  29. this.promise;
  30. }
  31. /**
  32. * Can be called by anyone holding this object to abort the underlying
  33. * operation. This is not cancellation, and will not necessarily result in
  34. * any work being undone. abort() should return a Promise which is resolved
  35. * when the underlying operation has been aborted. The returned Promise
  36. * should never be rejected.
  37. *
  38. * @return {!Promise}
  39. * @exportDoc
  40. */
  41. abort() {}
  42. /**
  43. * @param {function(boolean)} onFinal A callback to be invoked after the
  44. * operation succeeds or fails. The boolean argument is true
  45. * if the operation succeeded and false if it failed.
  46. * @return {!shaka.extern.IAbortableOperation<T>} Returns this.
  47. * @exportDoc
  48. */
  49. finally(onFinal) {}
  50. };