Skip to content

Commit

Permalink
feat: add method to get the stream cancellation token (#80)
Browse files Browse the repository at this point in the history
In some cases, the stream is transferred to a different context, making
it impossible to cancel from the current one. By making the
download_task_cancellation_token public, you can clone the token
beforehand, ensuring that cancellation remains possible regardless of
the context shift

---------

Co-authored-by: Austin Schey <[email protected]>
  • Loading branch information
PTRRR and aschey authored Aug 14, 2024
1 parent 3d5b648 commit 452239f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ impl<P: StorageProvider> StreamDownload<P> {
self.download_task_cancellation_token.cancel();
}

/// Get the [`CancellationToken`] for the download task.
pub fn get_cancellation_token(&self) -> CancellationToken {
self.download_task_cancellation_token.clone()
}

async fn from_make_stream<S, F, Fut>(
make_stream: F,
storage_provider: P,
Expand Down

0 comments on commit 452239f

Please sign in to comment.