Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: worker tries to open websocket before sending any request #114

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions packages/worker-api/src/sendRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
import { Request } from './interface.js';
import type {ShardIdentifier, IntegriteeTrustedCallSigned} from "@encointer/types";

export const sendWorkerRequest = (self: IWorker, clientRequest: any, parserType: string, options?: RequestOptions): Promise<any> =>{
export const sendWorkerRequest = async (self: IWorker, clientRequest: any, parserType: string, options?: RequestOptions): Promise<any> =>{
if( !self.isOpened ) {
await self.open();
}

const requestId = self.rqStack.push(parserType) + self.rsCount;
const timeout = options && options.timeout ? options.timeout : undefined;
return self.sendRequest(
Expand All @@ -20,9 +24,6 @@ export const sendWorkerRequest = (self: IWorker, clientRequest: any, parserType:
}

export const callGetter = async <T>(self: IWorker, workerMethod: WorkerMethod, _args: RequestArgs, requestOptions?: RequestOptions): Promise<T> => {
if( !self.isOpened ) {
await self.open();
}
const [getterType, method, parser] = workerMethod;
let result: Promise<any>;
let parserType: string = requestOptions?.debug ? 'raw': parser;
Expand All @@ -37,10 +38,6 @@ export const callGetter = async <T>(self: IWorker, workerMethod: WorkerMethod, _
}

export const sendTrustedCall = async <T>(self: IWorker, call: IntegriteeTrustedCallSigned, shard: ShardIdentifier, direct: boolean, parser: string, options: RequestOptions = {} as RequestOptions): Promise<T> => {
if( !self.isOpened ) {
await self.open();
}

let result: Promise<any>;
let parserType: string = options.debug ? 'raw': parser;

Expand Down
Loading