MCPcopy Create free account
hub / github.com/Snapchat/Valdi / callPromise

Method callPromise

valdi/src/valdi/runtime/JavaScript/ValueFunctionWithJSValue.cpp:281–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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();

Callers

nothing calls this directly

Calls 15

doJsCallMethod · 0.95
strongSmallRefFunction · 0.85
captureParametersFunction · 0.85
extractErrorMethod · 0.80
getContextFunction · 0.50
ErrorInterface · 0.50
ValueClass · 0.50
dataMethod · 0.45
sizeMethod · 0.45
fulfillMethod · 0.45

Tested by

no test coverage detected