File
Blob: src/workerd/jsg/iterator.c++
| 1 | // Copyright (c) 2017-2022 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | #include "iterator.h" |
| 6 | |
| 7 | namespace workerd::jsg { |
| 8 | |
| 9 | kj::Maybe<jsg::Promise<void>&> AsyncIteratorImpl::maybeCurrent() { |
| 10 | if (!pendingStack.empty()) { |
| 11 | return pendingStack.back(); |
| 12 | } |
| 13 | return kj::none; |
| 14 | } |
| 15 | |
| 16 | void AsyncIteratorImpl::pushCurrent(Promise<void> promise) { |
| 17 | pendingStack.push_back(kj::mv(promise)); |
| 18 | } |
| 19 | |
| 20 | void AsyncIteratorImpl::popCurrent() { |
| 21 | if (!pendingStack.empty()) { |
| 22 | pendingStack.pop_front(); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | void AsyncIteratorImpl::visitForGc(jsg::GcVisitor& visitor) { |
| 27 | visitor.visitAll(pendingStack); |
| 28 | } |
| 29 | |
| 30 | } // namespace workerd::jsg |