| 134 | ]; |
| 135 | |
| 136 | export function createWorkerHost< |
| 137 | T extends AsyncMethods, |
| 138 | H extends AsyncMethods & {initWorker: (height?: number) => Promise<void>}, |
| 139 | ApiConnection /* ApiPromiseConnection*/, |
| 140 | DS extends BaseDataSource = BaseDataSource, |
| 141 | >(extraWorkerFns: (keyof T)[], extraHostFns: H): WorkerHost<DefaultWorkerFunctions<ApiConnection, DS> & T> { |
| 142 | // Register these functions to be exposed to worker host |
| 143 | return WorkerHost.create<DefaultWorkerFunctions<ApiConnection, DS> & T, IBaseIndexerWorker & H>( |
| 144 | [ |
| 145 | // Have this first to not override the default functions |
| 146 | ...extraWorkerFns, |
| 147 | ...hostStoreKeys, |
| 148 | ...hostCacheKeys, |
| 149 | ...hostDynamicDsKeys, |
| 150 | ...hostUnfinalizedBlocksKeys, |
| 151 | ...hostMonitorKeys, |
| 152 | ...hostConnectionPoolStateKeys, |
| 153 | ], |
| 154 | { |
| 155 | // Have this first to not override the default functions |
| 156 | ...extraHostFns, |
| 157 | fetchBlock, |
| 158 | processBlock, |
| 159 | numFetchedBlocks, |
| 160 | numFetchingBlocks, |
| 161 | getStatus, |
| 162 | getMemoryLeft, |
| 163 | abortFetching, |
| 164 | }, |
| 165 | logger |
| 166 | ); |
| 167 | } |
| 168 | |
| 169 | export type TerminateableWorker<T extends IBaseIndexerWorker> = T & {terminate: () => Promise<number>}; |
| 170 | |