DownloadTask

public struct DownloadTask

Represents a task of an image downloading process.

  • The SessionDataTask object bounded to this download task. Multiple DownloadTasks could refer to a same sessionTask. This is an optimization in Kingfisher to prevent multiple downloading task for the same URL resource at the same time.

    When you cancel a DownloadTask, this SessionDataTask and its cancel token will be pass through. You can use them to identify the cancelled task.

    Declaration

    Swift

    public let sessionTask: SessionDataTask
  • The cancel token which is used to cancel the task. This is only for identify the task when it is cancelled. To cancel a DownloadTask, use cancel instead.

    Declaration

    Swift

    public let cancelToken: SessionDataTask.CancelToken
  • Cancel this task if it is running. It will do nothing if this task is not running.

    Note

    In Kingfisher, there is an optimization to prevent starting another download task if the target URL is being downloading. However, even when internally no new session task created, a DownloadTask will be still created and returned when you call related methods, but it will share the session downloading task with a previous task. In this case, if multiple DownloadTasks share a single session download task, cancelling a DownloadTask does not affect other DownloadTasks.

    If you need to cancel all DownloadTasks of a url, use ImageDownloader.cancel(url:). If you need to cancel all downloading tasks of an ImageDownloader, use ImageDownloader.cancelAll().

    Declaration

    Swift

    public func cancel()