-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df80970
commit 75fd0ad
Showing
5 changed files
with
53 additions
and
136 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function delay(ms: number) { | ||
return new Promise<void>(resolve => { | ||
setTimeout(() => { | ||
resolve() | ||
}, ms) | ||
}) | ||
} | ||
|
||
export function deadline<T>(p: Promise<T>, ms: number): Promise<T> { | ||
const controller = new AbortController() | ||
|
||
const d = delay(ms) | ||
.catch(() => {}) | ||
.then(() => Promise.reject(new Error())) | ||
|
||
return Promise.race([p.finally(() => controller.abort()), d]) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { unzip as _unzip, type Unzipped } from 'fflate' | ||
|
||
export function unzip(buf: ArrayBuffer) { | ||
const promise = new Promise<Unzipped>((resolve, reject) => { | ||
_unzip(new Uint8Array(buf), (err, data) => { | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve(data) | ||
} | ||
}) | ||
}) | ||
|
||
return promise | ||
} |