Skip to content

Refactor TaskPropertyAccessor to absorb cancellation token lifecycle #2496

@onevcat

Description

@onevcat

Summary

KingfisherWrapper.setImage(...) currently passes previousCancellationToken and setCancellationToken as standalone parameters in addition to TaskPropertyAccessor.

These token-related parameters belong to the same task lifecycle concern as:

  • setTaskIdentifier
  • getTaskIdentifier
  • setTask

The current shape works, but it creates parameter sprawl and makes the helper signature harder to read.

Proposed Direction

Fold cancellation-token access into TaskPropertyAccessor so the helper receives a single lifecycle accessor instead of splitting task state across:

  • taskAccessor
  • previousCancellationToken
  • setCancellationToken

Possible shape:

  • add token getter/setter accessors to TaskPropertyAccessor
  • let the helper cancel the previous token and store the new token through that accessor

Scope

This is a readability / maintainability cleanup only.
It should not change behavior.

Non-Goals

  • do not change the current stale-disk-cache semantics
  • do not refactor unrelated associated-object patterns in this issue
  • do not change public API surface

Affected Files

Likely at least:

  • Sources/Extensions/HasImageComponent+Kingfisher.swift
  • Sources/Extensions/ImageView+Kingfisher.swift
  • Sources/Extensions/NSTextAttachment+Kingfisher.swift
  • Sources/Extensions/CPListItem+Kingfisher.swift
  • Sources/Extensions/UIButton+Kingfisher.swift
  • Sources/Extensions/NSButton+Kingfisher.swift

Acceptance

  • helper signature becomes simpler
  • token lifecycle stays encapsulated with other task lifecycle accessors
  • no behavior change
  • existing stale cache tests continue to pass

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions