| 61 | } // namespace |
| 62 | |
| 63 | Status IteratorResource::GetNext(OpKernelContext* ctx, |
| 64 | std::vector<Tensor>* out_tensors, |
| 65 | bool* end_of_sequence) { |
| 66 | std::shared_ptr<State> captured_state; |
| 67 | { |
| 68 | tf_shared_lock l(mu_); |
| 69 | captured_state = iterator_state_; |
| 70 | } |
| 71 | if (captured_state->iterator) { |
| 72 | IteratorContext::Params params(ctx); |
| 73 | params.flr = captured_state->flr; |
| 74 | params.function_handle_cache = captured_state->function_handle_cache.get(); |
| 75 | params.resource_mgr = &captured_state->resource_mgr; |
| 76 | params.thread_factory = unbounded_thread_pool_.get_thread_factory(); |
| 77 | params.thread_pool = &unbounded_thread_pool_; |
| 78 | params.cancellation_manager = &captured_state->cancellation_manager; |
| 79 | std::function<void()> deregister_fn; |
| 80 | TF_RETURN_IF_ERROR(ConnectCancellationManagers(ctx->cancellation_manager(), |
| 81 | params.cancellation_manager, |
| 82 | &deregister_fn)); |
| 83 | auto cleanup = gtl::MakeCleanup(std::move(deregister_fn)); |
| 84 | return captured_state->iterator->GetNext(IteratorContext(std::move(params)), |
| 85 | out_tensors, end_of_sequence); |
| 86 | } |
| 87 | return errors::FailedPrecondition( |
| 88 | "GetNext() failed because the iterator has not been initialized. Ensure " |
| 89 | "that you have run the initializer operation for this iterator before " |
| 90 | "getting the next element."); |
| 91 | } |
| 92 | |
| 93 | Status IteratorResource::Save(SerializationContext* ctx, |
| 94 | IteratorStateWriter* writer) { |