future.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * A future similar to Python's asyncio.Future. Allows to resolve or reject
  19. * outside of the executor and query the current status.
  20. */
  21. interface Future<T> extends Promise<T> {
  22. /**
  23. * Return whether the future is done (resolved or rejected).
  24. */
  25. readonly done: boolean;
  26. /**
  27. * Resolve the future.
  28. */
  29. resolve(value?: T | PromiseLike<T>): void;
  30. /**
  31. * Reject the future.
  32. */
  33. reject(reason?: any): void;
  34. }
  35. interface FutureStatic {
  36. new<T>(executor?: (resolveFn: (value?: T | PromiseLike<T>) => void,
  37. rejectFn: (reason?: any) => void) => void,
  38. ): Future<T>
  39. withMinDuration<T>(promise: Promise<T>, minDuration: Number): Future<T>
  40. }
  41. declare var Future: FutureStatic;