Skip to content

Commit

Permalink
chore(transport): remove duplicated fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 authored and szymonlesisz committed Sep 4, 2024
1 parent 1a2fbf7 commit 29dab70
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/transport/src/sessions/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@ export class SessionsBackground extends TypedEmitter<{
}

private async releaseIntent(payload: ReleaseIntentRequest) {
const path = this.getPathFromSessions({ session: payload.session });
const pathResult = this.getPathBySession({ session: payload.session });

if (!path) {
return this.error(ERRORS.SESSION_NOT_FOUND);
if (!pathResult.success) {
return pathResult;
}
const { path } = pathResult.payload;

await this.waitInQueue();

Expand All @@ -226,23 +227,18 @@ export class SessionsBackground extends TypedEmitter<{
}

private getPathBySession({ session }: GetPathBySessionRequest) {
const path = this.getPathFromSessions({ session });
if (!path) {
return this.error(ERRORS.SESSION_NOT_FOUND);
}

return this.success({ path });
}

private getPathFromSessions({ session }: GetPathBySessionRequest) {
let path: string | undefined;
Object.keys(this.descriptors).forEach(pathKey => {
if (this.descriptors[pathKey]?.session === session) {
path = pathKey;
}
});

return path;
if (!path) {
return this.error(ERRORS.SESSION_NOT_FOUND);
}

return this.success({ path });
}

private startLock() {
Expand Down

0 comments on commit 29dab70

Please sign in to comment.