From 2e124917bb04483261659f242688db206fba9d7c Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Wed, 18 Nov 2020 00:55:40 +0800 Subject: [PATCH] server: Transmission: properly await tracker removal results --- .../Transmission/clientGatewayService.ts | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/server/services/Transmission/clientGatewayService.ts b/server/services/Transmission/clientGatewayService.ts index 230d873d..6d6603b8 100644 --- a/server/services/Transmission/clientGatewayService.ts +++ b/server/services/Transmission/clientGatewayService.ts @@ -238,31 +238,26 @@ class TransmissionClientGatewayService extends ClientGatewayService { } async setTorrentsTrackers({hashes, trackers}: SetTorrentsTrackersOptions): Promise { - const torrentsProcessed: Array = []; - // Remove existing trackers await this.clientRequestManager .getTorrents(hashes, ['trackers']) .then(this.processClientRequestSuccess, this.processClientRequestError) .then((torrents) => - torrents.forEach((torrent, index) => { - const hash = hashes[index]; - this.clientRequestManager - .setTorrentsProperties({ - ids: hash, - trackerRemove: torrent.trackers.map((tracker) => tracker.id), - }) - .then( - () => { - torrentsProcessed.push(hash); - }, - () => undefined, - ); - }), + Promise.all( + torrents.map(async (torrent, index) => { + await this.clientRequestManager + .setTorrentsProperties({ + ids: hashes[index], + trackerRemove: torrent.trackers.map((tracker) => tracker.id), + }) + .then(this.processClientRequestSuccess, this.processClientRequestError) + .catch(() => undefined); + }), + ), ); return this.clientRequestManager - .setTorrentsProperties({ids: torrentsProcessed, trackerAdd: trackers}) + .setTorrentsProperties({ids: hashes, trackerAdd: trackers}) .then(this.processClientRequestSuccess, this.processClientRequestError); }