MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / runPollOnce

Function runPollOnce

packages/node/src/backend/nodeBackendInline.ts:431–490  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

429 }
430
431 function runPollOnce(): void {
432 if (!started || disposed || stopRequested || fatal !== null) return;
433 if (engineId === null || native === null || discardBuffer === null) return;
434 if (pollActive) return;
435 pollActive = true;
436 try {
437 const outBuf = eventPool.length > 0 ? (eventPool.pop() ?? discardBuffer) : discardBuffer;
438 let written = -1;
439 const startMs = PERF_ENABLED ? performance.now() : 0;
440 try {
441 written = native.enginePollEvents(engineId, 0, new Uint8Array(outBuf));
442 } catch (err) {
443 failWith("enginePollEvents", -1, `engine_poll_events threw: ${safeDetail(err)}`);
444 return;
445 }
446 if (PERF_ENABLED) {
447 perfRecord("event_poll", performance.now() - startMs);
448 }
449 if (written === ZR_ERR_LIMIT) {
450 if (outBuf !== discardBuffer) eventPool.push(outBuf);
451 droppedSinceLast++;
452 schedulePoll(POLL_BUSY_MS);
453 return;
454 }
455 if (!Number.isInteger(written) || written > outBuf.byteLength) {
456 if (outBuf !== discardBuffer) eventPool.push(outBuf);
457 failWith(
458 "enginePollEvents",
459 -1,
460 `engine_poll_events returned invalid byte count: written=${String(written)} capacity=${String(outBuf.byteLength)}`,
461 );
462 return;
463 }
464 if (written < 0) {
465 if (outBuf !== discardBuffer) eventPool.push(outBuf);
466 failWith("enginePollEvents", written, "engine_poll_events failed");
467 return;
468 }
469 if (written === 0) {
470 if (outBuf !== discardBuffer) eventPool.push(outBuf);
471 schedulePoll(POLL_IDLE_MS);
472 return;
473 }
474 if (outBuf === discardBuffer) {
475 droppedSinceLast++;
476 schedulePoll(POLL_BUSY_MS);
477 return;
478 }
479 const waiter = eventWaiters.shift();
480 if (waiter !== undefined) {
481 waiter.resolve(buildBatch(outBuf, written, droppedSinceLast));
482 } else {
483 eventQueue.push({ batch: outBuf, byteLen: written, droppedSinceLast });
484 }
485 droppedSinceLast = 0;
486 schedulePoll(POLL_BUSY_MS);
487 } finally {
488 pollActive = false;

Callers 1

schedulePollFunction · 0.85

Calls 7

failWithFunction · 0.85
schedulePollFunction · 0.85
buildBatchFunction · 0.85
resolveMethod · 0.80
safeDetailFunction · 0.70
perfRecordFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected