@latticexyz/network / SyncWorker

# Class: SyncWorker<C>

# Type parameters

Name Type
C extends Components

# Implements

# Table of contents

# Constructors

  • constructor

# Properties

  • input$
  • output$
  • syncState

# Methods

  • init
  • setLoadingState
  • work

# Constructors

# constructor

new SyncWorker<C>()

# Type parameters

Name Type
C extends Components

# Defined in

workers/SyncWorker.ts:74

# Properties

# input$

Private input$: Subject<Input>

# Defined in

workers/SyncWorker.ts:70


# output$

Private output$: Subject<NetworkEvent<C>>

# Defined in

workers/SyncWorker.ts:71


# syncState

Private syncState: SyncStateStruct

# Defined in

workers/SyncWorker.ts:72

# Methods

# init

Private init(): Promise<void>

Start the sync process.

  1. Get config
  2. Load initial state 2.1 Get cache block number 2.2 Get snapshot block number 2.3 Load from more recent source
  3. Cach up to current block number by requesting events from RPC ( -> TODO: Replace with own service)
  4. Keep in sync 4.1 If available keep in sync with streaming service 4.2 Else keep in sync with RPC

# Returns

Promise<void>

# Defined in

workers/SyncWorker.ts:121


# setLoadingState

Private setLoadingState(loadingState, blockNumber?): void

Pass a loading state component update to the main thread. Can be used to indicate the initial loading state on a loading screen.

# Parameters

Name Type Default value Description
loadingState Partial<{ msg: string ; percentage: number ; state: SyncState }> undefined { state: SyncState, msg: Message to describe the current loading step. percentage: Number between 0 and 100 to describe the loading progress. }
blockNumber number 0 Optional: block number to pass in the component update.

# Returns

void

# Defined in

workers/SyncWorker.ts:89


# work

work(input$): Observable<NetworkEvent<C>[]>

# Parameters

Name Type
input$ Observable<Input>

# Returns

Observable<NetworkEvent<C>[]>

# Implementation of

DoWork.work

# Defined in

workers/SyncWorker.ts:321