Skip to content

Commit

Permalink
Pass timeout to timeout handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Apr 16, 2024
1 parent 79c2bd6 commit 037aeca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/@uppy/utils/src/ProgressTimeout.ts
Expand Up @@ -15,10 +15,11 @@ class ProgressTimeout {

constructor(
timeout: number,
timeoutHandler: Parameters<typeof setTimeout>[0],
// eslint-disable-next-line no-shadow
timeoutHandler: (timeout: number) => void,
) {
this.#timeout = timeout
this.#onTimedOut = timeoutHandler
this.#onTimedOut = () => timeoutHandler(timeout)
}

progress(): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/utils/src/fetcher.ts
Expand Up @@ -44,7 +44,7 @@ export type FetcherOptions = {
) => void | Promise<void>

/** Called when no XMLHttpRequest upload progress events have been received for `timeout` ms. */
onTimeout?: () => void
onTimeout?: (timeout: number) => void

/** Signal to abort the upload. */
signal?: AbortSignal
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/xhr-upload/src/index.ts
Expand Up @@ -214,8 +214,8 @@ export default class XHRUpload<
try {
const res = await fetcher(url, {
...options,
onTimeout: () => {
const seconds = Math.ceil(options.timeout! / 1000)
onTimeout: (timeout) => {
const seconds = Math.ceil(timeout / 1000)
const error = new Error(this.i18n('uploadStalled', { seconds }))
this.uppy.emit('upload-stalled', error, files)
},
Expand Down

0 comments on commit 037aeca

Please sign in to comment.