-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from StarfilesFileSharing/alpha
Alpha
- Loading branch information
Showing
6 changed files
with
19 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,16 +37,20 @@ class Utils { | |
const os = await import("https://deno.land/[email protected]/node/os.ts"); | ||
return os.freemem() > (fileSize + this._config.memoryThreshold); | ||
}; | ||
static promiseWithTimeout = async <T>(promise: Promise<T>, timeoutDuration: number): Promise<T | ErrorTimeout> => | ||
await Promise.race([ | ||
promise, | ||
new Promise<never>((_resolve, reject) => | ||
setTimeout( | ||
() => reject(new ErrorTimeout()), | ||
timeoutDuration, | ||
) | ||
), | ||
]); | ||
|
||
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 estimateHops = (signalStrength: number): { hop: number | null; certainty: number } => { | ||
const hopData = [ | ||
|