Skip to content

Commit

Permalink
Merge pull request #64 from futuredapp/housekeep/internal-publisher
Browse files Browse the repository at this point in the history
Housekeep: Make endpoint publisher internal
  • Loading branch information
mkj-is authored Jan 26, 2021
2 parents f8c9f6f + 5e5fcf1 commit f4d9bfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Sources/FTAPIKit/Combine/EndpointPublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import Combine

@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
extension Publishers {
public struct Endpoint<R, E: Error>: Publisher {
public typealias Output = R
public typealias Failure = E
struct Endpoint<R, E: Error>: Publisher {
typealias Output = R
typealias Failure = E

typealias Builder = (@escaping (Result<R, E>) -> Void) -> URLSessionTask?

let builder: Builder

public func receive<S>(subscriber: S) where S: Subscriber, Failure == S.Failure, Output == S.Input {
func receive<S>(subscriber: S) where S: Subscriber, Failure == S.Failure, Output == S.Input {
let subscription = EndpointSubscription(subscriber: subscriber, builder: builder)
subscriber.receive(subscription: subscription)
}
Expand Down
12 changes: 8 additions & 4 deletions Sources/FTAPIKit/Combine/URLServer+Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@ import Combine

@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
public extension URLServer {
func publisher(endpoint: Endpoint) -> Publishers.Endpoint<Void, ErrorType> {
func publisher(endpoint: Endpoint) -> AnyPublisher<Void, ErrorType> {
Publishers.Endpoint { completion in
self.call(endpoint: endpoint, completion: completion)
}
.eraseToAnyPublisher()
}

func publisher(data endpoint: Endpoint) -> Publishers.Endpoint<Data, ErrorType> {
func publisher(data endpoint: Endpoint) -> AnyPublisher<Data, ErrorType> {
Publishers.Endpoint { completion in
self.call(data: endpoint, completion: completion)
}
.eraseToAnyPublisher()
}

func publisher<EP: ResponseEndpoint>(response endpoint: EP) -> Publishers.Endpoint<EP.Response, ErrorType> {
func publisher<EP: ResponseEndpoint>(response endpoint: EP) -> AnyPublisher<EP.Response, ErrorType> {
Publishers.Endpoint { completion in
self.call(response: endpoint, completion: completion)
}
.eraseToAnyPublisher()
}

func publisher(download endpoint: Endpoint) -> Publishers.Endpoint<URL, ErrorType> {
func publisher(download endpoint: Endpoint) -> AnyPublisher<URL, ErrorType> {
Publishers.Endpoint { completion in
self.download(endpoint: endpoint, completion: completion)
}
.eraseToAnyPublisher()
}
}

Expand Down

0 comments on commit f4d9bfb

Please sign in to comment.