private-async-helpers.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @license
  3. * Copyright 2021 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /**
  7. * Helper to iterate an AsyncIterable in its own closure.
  8. * @param iterable The iterable to iterate
  9. * @param callback The callback to call for each value. If the callback returns
  10. * `false`, the loop will be broken.
  11. */
  12. export declare const forAwaitOf: <T>(iterable: AsyncIterable<T>, callback: (value: T) => Promise<boolean>) => Promise<void>;
  13. /**
  14. * Holds a reference to an instance that can be disconnected and reconnected,
  15. * so that a closure over the ref (e.g. in a then function to a promise) does
  16. * not strongly hold a ref to the instance. Approximates a WeakRef but must
  17. * be manually connected & disconnected to the backing instance.
  18. */
  19. export declare class PseudoWeakRef<T> {
  20. private _ref?;
  21. constructor(ref: T);
  22. /**
  23. * Disassociates the ref with the backing instance.
  24. */
  25. disconnect(): void;
  26. /**
  27. * Reassociates the ref with the backing instance.
  28. */
  29. reconnect(ref: T): void;
  30. /**
  31. * Retrieves the backing instance (will be undefined when disconnected)
  32. */
  33. deref(): T | undefined;
  34. }
  35. /**
  36. * A helper to pause and resume waiting on a condition in an async function
  37. */
  38. export declare class Pauser {
  39. private _promise?;
  40. private _resolve?;
  41. /**
  42. * When paused, returns a promise to be awaited; when unpaused, returns
  43. * undefined. Note that in the microtask between the pauser being resumed
  44. * an an await of this promise resolving, the pauser could be paused again,
  45. * hence callers should check the promise in a loop when awaiting.
  46. * @returns A promise to be awaited when paused or undefined
  47. */
  48. get(): Promise<void> | undefined;
  49. /**
  50. * Creates a promise to be awaited
  51. */
  52. pause(): void;
  53. /**
  54. * Resolves the promise which may be awaited
  55. */
  56. resume(): void;
  57. }
  58. //# sourceMappingURL=private-async-helpers.d.ts.map