mapbox / mapbox/mapbox-directions-swift

Directions methods should return some kind of Cancellable protocol instead of URLSessionDataTask

Open
#465 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

op-ex
Dominant language
Swift
Stars
206
Forks
99
Avg merge
7h 54m
Merged PRs (30d)
3

Description

Right now all methods in Directions class return URLSessionDataTask instance directly. This makes subclassing Directions harder, as it leaks internal implementation of it (i.e. it uses URLSession underneath). As far as I noticed, returned tasks are only used for cancelling them, so it is possible to just introduce Cancellable protocol in form of:

public protocol Cancellable {
    func cancel()
}

with extension for URLSessionDataTask:

extension URLSessionDataTask: Cancellable {}

and declare all methods to return it instead of URLSessionDataTask. This will allow to make subclasses of Directions (e.g. one using other web service than Mapbox's one or some offline solution) without being tied to URLSession.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Directions class and inventorying its methods that return URLSessionDataTask. Review how callers use those returned tasks, then update the public return type to the proposed Cancellable abstraction and verify that cancellation still works across the affected methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api, backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.