| 276 | ~State() {} |
| 277 | |
| 278 | void Start() { |
| 279 | int branch = branch_; |
| 280 | // The last branch is the default branch. |
| 281 | if (branch < 0 || branch >= branch_handles_.size()) { |
| 282 | branch = branch_handles_.size() - 1; |
| 283 | } |
| 284 | rets_.clear(); |
| 285 | profiler::TraceMe trace_me( |
| 286 | [&] { |
| 287 | return absl::StrCat("CaseOp #parent_step_id=", ctx_->step_id(), |
| 288 | ",function_step_id=", opts_.step_id, "#"); |
| 289 | }, |
| 290 | /*level=*/2); |
| 291 | lib_->Run( |
| 292 | // Evaluate one of the branch. |
| 293 | opts_, branch_handles_[branch], args_, &rets_, |
| 294 | // Done callback |
| 295 | [this](Status s) { |
| 296 | if (s.ok()) { |
| 297 | s = SetOutputs(kernel_, ctx_, rets_); |
| 298 | } |
| 299 | ctx_->SetStatus(s); |
| 300 | DoneCallback captured_done(std::move(done_)); |
| 301 | delete this; |
| 302 | captured_done(); |
| 303 | }); |
| 304 | } |
| 305 | |
| 306 | private: |
| 307 | CaseOp* const kernel_; |