| 48 | } |
| 49 | |
| 50 | void Compute(OpKernelContext* context) override { |
| 51 | if (!IsCancellable()) { |
| 52 | ResourceOpKernel<ReaderInterface>::Compute(context); |
| 53 | } else { |
| 54 | // Install cancellation |
| 55 | CancellationManager* cm = context->cancellation_manager(); |
| 56 | CancellationToken token = cm->get_cancellation_token(); |
| 57 | bool already_cancelled = |
| 58 | !cm->RegisterCallback(token, [this]() { this->Cancel(); }); |
| 59 | |
| 60 | if (!already_cancelled) { |
| 61 | ResourceOpKernel<ReaderInterface>::Compute(context); |
| 62 | } else { |
| 63 | context->SetStatus(errors::Cancelled("read operation was cancelled")); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | virtual bool IsCancellable() const { return false; } |
nothing calls this directly
no test coverage detected