Skip to content

Commit

Permalink
Be able to abort async operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Sep 3, 2024
1 parent 299d6a5 commit 7adc563
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
8 changes: 7 additions & 1 deletion lib/s3-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type ByteRangeRequest = [number, number];
*/
export class S3Request implements IRangeRequestClient {

private readonly abortController = new AbortController();

constructor(private s3: S3Client, private objRequest: GetObjectRequest) {
}

Expand Down Expand Up @@ -64,6 +66,10 @@ export class S3Request implements IRangeRequestClient {
};
const command = new GetObjectCommand(rangedRequest)

return this.s3.send(command);
return this.s3.send(command, { abortSignal: this.abortController.signal });
}

abort(): void {
this.abortController.abort();
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"dependencies": {
"@aws-sdk/credential-providers": "^3.631.0",
"@biomejs/biome": "^1.8.3",
"@tokenizer/range": "^0.8.0",
"strtok3": "^8.1.0"
"@tokenizer/range": "^0.10.0",
"strtok3": "^9.0.0"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.631.0",
Expand All @@ -68,7 +68,7 @@
"del-cli": "^5.1.0",
"file-type": "^19.4.1",
"mocha": "^10.7.3",
"music-metadata": "^10.2.0",
"music-metadata": "^10.3.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
},
Expand Down
62 changes: 31 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1591,13 +1591,13 @@ __metadata:
languageName: node
linkType: hard

"@tokenizer/range@npm:^0.8.0":
version: 0.8.0
resolution: "@tokenizer/range@npm:0.8.0"
"@tokenizer/range@npm:^0.10.0":
version: 0.10.0
resolution: "@tokenizer/range@npm:0.10.0"
dependencies:
debug: "npm:^4.3.5"
strtok3: "npm:^8.0.1"
checksum: 10c0/65a9a9712eb12c468cee84fc7ce295b034468a9416922b4d4052e371249ddeedb45fbb0c967cab41e1909ffa59000b9ffae12f70befe0a75169616707bf6207a
debug: "npm:^4.3.6"
strtok3: "npm:^9.0.0"
checksum: 10c0/3e036c79f20cd3a88dd58fa249c5d2ce1d986d85a4678f97d40db67c3eba4a2e9b5eaf70869b78919e61e13573a1209de96c421228d39b0025a540df606466c7
languageName: node
linkType: hard

Expand All @@ -1608,7 +1608,7 @@ __metadata:
"@aws-sdk/client-s3": "npm:^3.631.0"
"@aws-sdk/credential-providers": "npm:^3.631.0"
"@biomejs/biome": "npm:^1.8.3"
"@tokenizer/range": "npm:^0.8.0"
"@tokenizer/range": "npm:^0.10.0"
"@tokenizer/token": "npm:^0.3.0"
"@types/chai": "npm:^4.3.17"
"@types/mocha": "npm:^10.0.7"
Expand All @@ -1617,8 +1617,8 @@ __metadata:
del-cli: "npm:^5.1.0"
file-type: "npm:^19.4.1"
mocha: "npm:^10.7.3"
music-metadata: "npm:^10.2.0"
strtok3: "npm:^8.1.0"
music-metadata: "npm:^10.3.1"
strtok3: "npm:^9.0.0"
ts-node: "npm:^10.9.2"
typescript: "npm:^5.5.4"
peerDependencies:
Expand Down Expand Up @@ -2111,7 +2111,7 @@ __metadata:
languageName: node
linkType: hard

"debug@npm:4, debug@npm:^4.3.4":
"debug@npm:4, debug@npm:^4.3.4, debug@npm:^4.3.6":
version: 4.3.6
resolution: "debug@npm:4.3.6"
dependencies:
Expand Down Expand Up @@ -3201,9 +3201,9 @@ __metadata:
languageName: node
linkType: hard

"music-metadata@npm:^10.2.0":
version: 10.2.0
resolution: "music-metadata@npm:10.2.0"
"music-metadata@npm:^10.3.1":
version: 10.3.1
resolution: "music-metadata@npm:10.3.1"
dependencies:
"@tokenizer/token": "npm:^0.3.0"
content-type: "npm:^1.0.5"
Expand All @@ -3213,7 +3213,7 @@ __metadata:
strtok3: "npm:^8.1.0"
token-types: "npm:^6.0.0"
uint8array-extras: "npm:^1.4.0"
checksum: 10c0/0278cedd224d089e1a07fad16209f85abb687269c0f1781810e82ebe5e4a65d3e0fc20ceb3efadd076e1582c8baab4a2839853873e4c14ec996c125cbbc29e3b
checksum: 10c0/013cd6bc012d5a79c7c65a11bf6dd10fdfdddc4397bdb763470c7c2630787158655fe1d6d1ce172ddc49a3c38aa5160396e76570bef18601bdf6a168ba1e1ac1
languageName: node
linkType: hard

Expand Down Expand Up @@ -3397,20 +3397,20 @@ __metadata:
languageName: node
linkType: hard

"peek-readable@npm:^5.1.3":
version: 5.1.3
resolution: "peek-readable@npm:5.1.3"
checksum: 10c0/4697a0e50778171467c0cdb3059c0810809787ae0dcbb4d44316dd2846be1829f62a790d6e9f8c9600a91aca74520ece7731b5914e3180ca1364268d168bd0e3
languageName: node
linkType: hard

"peek-readable@npm:^5.1.4":
version: 5.1.4
resolution: "peek-readable@npm:5.1.4"
checksum: 10c0/19015142b2f2556bec8b51c53111209bd6d774181df26dbf68908495819e35f4103e83915aa7ea35505d2a65d2712f2ab58f36b329cf61219c012621e65211b3
languageName: node
linkType: hard

"peek-readable@npm:^5.2.0":
version: 5.2.0
resolution: "peek-readable@npm:5.2.0"
checksum: 10c0/7647d56786c94fc7f5f39923ef5f6ed1da7be92a2c221b743db74f1517821b1e944cc965d8f018a7e6984d969b6ced8a0c421aece7996c0b1981eac9daa4c323
languageName: node
linkType: hard

"picomatch@npm:^2.0.4":
version: 2.2.1
resolution: "picomatch@npm:2.2.1"
Expand Down Expand Up @@ -3789,16 +3789,6 @@ __metadata:
languageName: node
linkType: hard

"strtok3@npm:^8.0.1":
version: 8.0.1
resolution: "strtok3@npm:8.0.1"
dependencies:
"@tokenizer/token": "npm:^0.3.0"
peek-readable: "npm:^5.1.3"
checksum: 10c0/a5ff7213a677a206dddebd23645b7ccbb54995707c916abc18bea49d347235fd2e50cf673e971b3f2c3f4f023b2a89451c23820bdd77c790460168d692e6f7e5
languageName: node
linkType: hard

"strtok3@npm:^8.1.0":
version: 8.1.0
resolution: "strtok3@npm:8.1.0"
Expand All @@ -3809,6 +3799,16 @@ __metadata:
languageName: node
linkType: hard

"strtok3@npm:^9.0.0":
version: 9.0.0
resolution: "strtok3@npm:9.0.0"
dependencies:
"@tokenizer/token": "npm:^0.3.0"
peek-readable: "npm:^5.2.0"
checksum: 10c0/7d7cde9c5a3b195131f3652c8b0cb20d96e80b10d30a19294379e4302d0d4952bdc24a516c8a6cfa82bcb96f5b47e49ec917e8cc23c81052044a2ec41d15fb30
languageName: node
linkType: hard

"supports-color@npm:^5.3.0":
version: 5.5.0
resolution: "supports-color@npm:5.5.0"
Expand Down

0 comments on commit 7adc563

Please sign in to comment.