y-tinypool
v0.0.1
Published
Execute Y.js in tinypool
Downloads
198
Readme
y-tinypool
Run Yjs update operations (merge / apply) in tinypool worker threads.
- Parallel Yjs binary update processing with
worker_threads mergeUpdates(updates)for fast update mergingapplyUpdates(updates)for producing final update after sequential apply- Structured error result (
ok: false) with optionalskipInvalidUpdatesandtimeout
Install
npm i y-tinypoolUsage
import * as Y from 'yjs';
import { YTinypool } from 'y-tinypool';
const pool = new YTinypool();
const updates: Uint8Array[] = [];
const source = new Y.Doc();
source.on('update', (u: Uint8Array) => updates.push(u));
const text = source.getText('content');
text.insert(0, 'Hello');
text.insert(5, ' Tiny');
text.insert(10, 'pool');
const merged = await pool.mergeUpdates(updates);
if (merged.ok) {
const doc = new Y.Doc();
Y.applyUpdate(doc, merged.update);
console.log(doc.getText('content').toString()); // Hello Tinypool
} else {
console.error(merged.error);
}
await pool.destroy();import * as Y from 'yjs';
import { YTinypool } from 'y-tinypool';
const pool = new YTinypool({ skipInvalidUpdates: true });
const updates: Uint8Array[] = [
Uint8Array.from([1, 2, 3]), // invalid sample
// ...valid updates
];
const applied = await pool.applyUpdates(updates, { timeout: 1000 });
if (applied.ok) {
const doc = new Y.Doc();
Y.applyUpdate(doc, applied.update);
console.log('skip logs:', applied.skips);
} else {
console.error(applied.error);
}
await pool.destroy();License
MIT License © 2026 XLor
