Move to websocket for requests to signal server

This commit is contained in:
Fedor Indutny 2021-07-28 14:37:09 -07:00 committed by GitHub
parent 8449f343a6
commit 1c1d0e2da0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 1892 additions and 1336 deletions

View file

@ -0,0 +1,38 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* eslint-disable no-restricted-syntax */
import { explodePromise } from './explodePromise';
export interface IController {
abort(): void;
}
export class AbortableProcess<Result> implements IController {
private abortReject: (error: Error) => void;
public readonly resultPromise: Promise<Result>;
constructor(
private readonly name: string,
private readonly controller: IController,
resultPromise: Promise<Result>
) {
const {
promise: abortPromise,
reject: abortReject,
} = explodePromise<Result>();
this.abortReject = abortReject;
this.resultPromise = Promise.race([abortPromise, resultPromise]);
}
public abort(): void {
this.controller.abort();
this.abortReject(new Error(`Process "${this.name}" was aborted`));
}
public getResult(): Promise<Result> {
return this.resultPromise;
}
}