| 102 | } |
| 103 | |
| 104 | async pop(): Promise<T> { |
| 105 | let element: T; |
| 106 | if (this.available > 0) { |
| 107 | element = this.#elements.pop()!; |
| 108 | } else { |
| 109 | // If there are not elements left in the stack, it will await the call until |
| 110 | // at least one is restored and then return it |
| 111 | const d = Promise.withResolvers<T>(); |
| 112 | this.#queue.push(d); |
| 113 | element = await d.promise; |
| 114 | } |
| 115 | |
| 116 | if (!(await this.#checkElementInitialization(element))) { |
| 117 | await this.#initializeElement(element); |
| 118 | } |
| 119 | return element; |
| 120 | } |
| 121 | |
| 122 | push(value: T): void { |
| 123 | // If an element has been requested while the stack was empty, indicate |