@magmacomputing/tempo-plugin-sync
This is a Community plugin for the Tempo library that provides lock-free, nanosecond-accurate cross-thread time synchronization using SharedArrayBuffer and Atomics.
Perfect For
High-frequency trading platforms, real-time multiplayer game servers, distributed microservice tracing, and extreme-precision scientific telemetry.
Installation
bash
npm install @magmacomputing/tempo-plugin-syncUsage
typescript
import { Tempo } from '@magmacomputing/tempo';
import { SyncPlugin } from '@magmacomputing/tempo-plugin-sync';
Tempo.init({
plugins: [SyncPlugin]
});
// Master Thread: Start the clock
const clock = Tempo.sync.startClock({ updateIntervalMs: 1 });
const buffer = clock.buffer; // Pass this SharedArrayBuffer to your workersReading from Worker Threads
To read the synchronized time from inside a worker thread, pass the SharedArrayBuffer via workerData and instantiate an AtomicReader.
typescript
// worker.ts
import { workerData } from 'node:worker_threads';
import { AtomicReader } from '@magmacomputing/tempo-plugin-sync';
// Hydrate the reader using the master buffer
const reader = new AtomicReader(workerData.buffer);
// 1. Get raw milliseconds (O(1) Atomic Read)
const ms = reader.now();
// 2. Get high-precision BigInt nanoseconds
const ns = reader.nowNano();
// 3. Hydrate a brand new Tempo instance with exact precision
const t = reader.getTempo();Licensing
This is a Community plugin. It is completely free and open-source for personal and commercial use. No license token is required.
For commercial licensing options, please contact Magma Computing.