Skip to content

Commit

Permalink
Merge pull request #174 from StarfilesFileSharing/alpha
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
QuixThe2nd authored Nov 16, 2024
2 parents 575f58a + e23ba3d commit 9e5e708
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,11 @@ class Utils {
return os.freemem() > (fileSize + this._config.memoryThreshold);
};

static async promiseWithTimeout<T>(promise: Promise<T>, timeoutDuration: number): Promise<T | ErrorTimeout> {
try {
return await Promise.race<T | ErrorTimeout>([
promise,
new Promise((_, reject) => {
setTimeout(() => reject(new ErrorTimeout()), timeoutDuration);
}),
]);
} catch (error) {
if (error instanceof ErrorTimeout) return error;
else throw error;
}
}
static promiseWithTimeout = <T>(promise: Promise<T>, timeoutMs: number): Promise<T | ErrorTimeout> => {
const timeoutPromise = new Promise<ErrorTimeout>((resolve) => setTimeout(() => resolve(new ErrorTimeout()), timeoutMs));

return Promise.race([promise, timeoutPromise]);
};

static estimateHops = (signalStrength: number): { hop: number | null; certainty: number } => {
const hopData = [
Expand Down

0 comments on commit 9e5e708

Please sign in to comment.