Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MoyaPublisher creates network request on every demand update #2352

@michalmlu

Description

@michalmlu

MoyaPublisher shouldn't create a network request if it receives a request demand larger then .none. It should do that only if no previous demand greater than .none was received.

        func request(_ demand: Subscribers.Demand) {
            guard demand > .none else { return }

            cancellable = performCall()
        }

I suggest changing the above code fragment to something like the following

        func request(_ demand: Subscribers.Demand) {
            guard demand > .none && cancellable == nil else { return }

            cancellable = performCall()
        }

This would be aligned with the way dataTaskPublisher works in URLSession. Subsequent subscribers get new subscriptions and new network requests are made for them, but if the same subscriber updates it's demand by calling the request(newDemand) method no new network request gets created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions