| 279 | [self = strongSmallRef(this), |
| 280 | taskScheduler, |
| 281 | parameters = captureParameters(parameters, parametersSize), |
| 282 | call, |
| 283 | skipIfTimedOut](auto& jsEntry) { |
| 284 | auto abandoned = call->state.load(std::memory_order_acquire) == DeadlineCall::State::TimedOut; |
| 285 | auto result = Value::undefined(); |
| 286 | if (!abandoned || !skipIfTimedOut) { |
| 287 | MainThreadBatchAllowScope mainThreadBatchAllowScope; |
| 288 | result = self->doJsCall(jsEntry, parameters.data(), parameters.size(), nullptr, abandoned); |
| 289 | } |
| 290 | |
| 291 | auto expected = DeadlineCall::State::Pending; |
| 292 | if (call->state.compare_exchange_strong(expected, DeadlineCall::State::Completed)) { |
| 293 | call->promise.set_value(Result(std::move(result))); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | // The waiter gave up on this call. It only fails later calls fast while we are overdue, |
| 298 | // so this is where the JS thread proves it is responsive again. getFunctionName() is |
| 299 | // safe here: this is the JS thread, the only writer of its lazy cache. |
| 300 | auto stillOverdue = taskScheduler->onOverdueDeadlineCallCompleted(); |
| 301 | if (stillOverdue == 0) { |
| 302 | [[maybe_unused]] auto failedFast = taskScheduler->takeFastFailedDeadlineCalls(); |
| 303 | [[maybe_unused]] auto lateByMs = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 304 | std::chrono::steady_clock::now() - call->dispatchedAt) |
| 305 | .count(); |
| 306 | VALDI_WARN(self->getContext()->getLogger(), |
| 307 | "JS thread caught up on overdue sync call to '{}' {}ms after dispatch; {} bounded calls " |
| 308 | "were failed fast meanwhile", |
| 309 | self->getFunctionName(), |
| 310 | lateByMs, |
| 311 | failedFast); |
| 312 | } |
| 313 | }); |
| 314 | |
| 315 | if (std::future_status::ready == future.wait_until(deadline)) { |
| 316 | return future.get(); |
nothing calls this directly
no test coverage detected