web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.0 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  7. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  8. var Promise = global[Symbol.for('jest-native-promise')] || global.Promise;
  9. function _defineProperty(obj, key, value) {
  10. if (key in obj) {
  11. Object.defineProperty(obj, key, {
  12. value: value,
  13. enumerable: true,
  14. configurable: true,
  15. writable: true
  16. });
  17. } else {
  18. obj[key] = value;
  19. }
  20. return obj;
  21. }
  22. /**
  23. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  24. *
  25. * This source code is licensed under the MIT license found in the
  26. * LICENSE file in the root directory of this source tree.
  27. */
  28. class CancelError extends Error {
  29. constructor() {
  30. super('Promise was canceled');
  31. this.name = 'CancelError';
  32. }
  33. }
  34. class PCancelable extends Promise {
  35. constructor(executor) {
  36. super(resolve => resolve());
  37. _defineProperty(this, '_pending', true);
  38. _defineProperty(this, '_canceled', false);
  39. _defineProperty(this, '_promise', void 0);
  40. _defineProperty(this, '_cancel', void 0);
  41. _defineProperty(this, '_reject', () => {});
  42. this._promise = new Promise((resolve, reject) => {
  43. this._reject = reject;
  44. return executor(
  45. fn => {
  46. this._cancel = fn;
  47. },
  48. val => {
  49. this._pending = false;
  50. resolve(val);
  51. },
  52. err => {
  53. this._pending = false;
  54. reject(err);
  55. }
  56. );
  57. });
  58. }
  59. then(onFulfilled, onRejected) {
  60. return this._promise.then(onFulfilled, onRejected);
  61. }
  62. catch(onRejected) {
  63. return this._promise.catch(onRejected);
  64. }
  65. cancel() {
  66. if (!this._pending || this._canceled) {
  67. return;
  68. }
  69. if (typeof this._cancel === 'function') {
  70. try {
  71. this._cancel();
  72. } catch (err) {
  73. this._reject(err);
  74. }
  75. }
  76. this._canceled = true;
  77. this._reject(new CancelError());
  78. }
  79. }
  80. exports.default = PCancelable;