Documentation / @etherfold/browser / hostIndexerInThisWorker
Function: hostIndexerInThisWorker() ​
hostIndexerInThisWorker<
ABI,ProcessResultType,ProcessorConfig>(spec):IndexerHost<ABI,ProcessResultType,ProcessorConfig>
Defined in: packages/browser/src/host/dedicatedWorker.ts:144
RUN THE INDEXER HERE, in the dedicated worker this is called from. The whole of what an app's worker entry point does.
// indexer.worker.ts -- the one file an app writes for this
import {createBrowserStateStore, hostIndexerInThisWorker} from '@etherfold/browser';
import {EntityEventProcessor} from '@etherfold/processor-entities';
import {openForWriting} from '@etherfold/state-store';
import {processor, source, provider} from './my-app.js';
hostIndexerInThisWorker({
createState: async (context, {signal}) =>
openForWriting(await createBrowserStateStore(processor.entities), {signal}),
createProcessor: (store) => new EntityEventProcessor(store, processor),
provider,
source,
});The processor crosses as an IMPORT and never as a message, because it is code and closures (ADR-0082).
Or the TAB hands over the provider and the settings ​
The provider and the cloneable settings may be LEFT OUT here, and the host then waits for the tab to send them when it connects: the chain as a MessagePort (a wallet's provider served by the tab, or a node in another worker), and source, config, publication, catchUpWithinSeconds and the rest of HostSettings. What stays here is the code.
// indexer.worker.ts
hostIndexerInThisWorker({
createState: async (context, {signal}) =>
openForWriting(await createBrowserStateStore(processor.entities), {signal}),
createProcessor: (store) => new EntityEventProcessor(store, processor),
});
// the tab
const indexer = connectToIndexerHost(dedicatedWorkerHost(() => new Worker(...)), {
provider: window.ethereum,
settings: {source, config, publication: {locations: [PUBLICATION]}},
});A value given in both places must agree, or the tab's connect is refused naming it (HostSettingsConflictError).
The store is opened for WRITING here, which is what makes the host the writer and every tab a reader.
Type Parameters ​
ABI ​
ABI extends Abi
ProcessResultType ​
ProcessResultType
ProcessorConfig ​
ProcessorConfig = undefined
Parameters ​
spec ​
HostedIndexerSpec<ABI, ProcessResultType, ProcessorConfig>
Returns ​
IndexerHost<ABI, ProcessResultType, ProcessorConfig>