Skip to content

Commit

Permalink
disposable v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-zethraeus committed Dec 22, 2022
1 parent 5ac9aae commit b4596e6
Show file tree
Hide file tree
Showing 30 changed files with 108 additions and 140 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/GoodHatsLLC/Disposable.git",
"state" : {
"revision" : "2280c49e0b09b3ecd003a7c8471a42c30d66629f",
"version" : "0.1.0"
"revision" : "65399859f05b1c4750b4df8c9d9f1833cf7b520c",
"version" : "0.3.0"
}
}
],
Expand Down
11 changes: 3 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,24 @@ let package = Package(
name: "Emitter",
targets: [
"Emitter",
"EmitterInterface",
]
),
.library(
name: "EmitterInterface",
targets: ["EmitterInterface"]
),
],
dependencies: [
.package(url: "https://github.com/GoodHatsLLC/Disposable.git", from: "0.1.0"),
.package(url: "https://github.com/GoodHatsLLC/Disposable.git", from: "0.3.0"),
],
targets: [
.target(
name: "Emitter",
dependencies: [
"Disposable",
"EmitterInterface",
"Disposable",
]
),
.target(
name: "EmitterInterface",
dependencies: [
.product(name: "DisposableInterface", package: "Disposable"),
"Disposable",
]
),
.testTarget(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Emitter/Operators/AsyncValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension Emitter {

continuation.onTermination = { _ in
Task {
await disposable.dispose()
disposable.dispose()
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions Sources/Emitter/Operators/CombineLatest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Emitter {
// MARK: - Emitters.CombineLatest

extension Emitters {
@MainActor

public struct CombineLatest<UpstreamA: Emitter, UpstreamB: Emitter>: Emitter
where UpstreamA.Output: Sendable, UpstreamB.Output: Sendable
{
Expand All @@ -32,7 +32,7 @@ extension Emitters {
public func subscribe<S: Subscriber>(_ subscriber: S)
-> AnyDisposable where S.Value == Output
{
let stage = DisposalStage()
let stage = DisposableStage()
let sub = Sub(downstream: subscriber)
let mapA = Proxy(downstream: sub, joinInit: JoinSubInput.a)
let mapB = Proxy(downstream: sub, joinInit: JoinSubInput.b)
Expand All @@ -51,7 +51,6 @@ extension Emitters {
case b(OutputB)
}

@MainActor
private final class Sub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{
Expand Down Expand Up @@ -89,7 +88,6 @@ extension Emitters {

}

@MainActor
private struct Proxy<UpstreamValue, Downstream: Subscriber>: Subscriber where Downstream.Value == JoinSubInput {

fileprivate init(
Expand Down
13 changes: 6 additions & 7 deletions Sources/Emitter/Operators/CompactMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import EmitterInterface

extension Emitter {
public func compactMap<NewOutput: Sendable>(
transformer: @escaping @MainActor (Output) -> NewOutput?
transformer: @escaping (Output) -> NewOutput?
) -> some Emitter<NewOutput> {
Emitters.CompactMap<Self, NewOutput>(upstream: self, transformer: transformer)
}
Expand All @@ -14,18 +14,17 @@ extension Emitter {
extension Emitters {
// MARK: - CompactMap

@MainActor
public struct CompactMap<Upstream: Emitter, Output: Sendable>: Emitter {

init(
upstream: Upstream,
transformer: @escaping @MainActor (Upstream.Output) -> Output?
transformer: @escaping (Upstream.Output) -> Output?
) {
self.transformer = transformer
self.upstream = upstream
}

public let transformer: @MainActor (Upstream.Output) -> Output?
public let transformer: (Upstream.Output) -> Output?
public let upstream: Upstream

public func subscribe<S: Subscriber>(_ subscriber: S)
Expand All @@ -35,11 +34,11 @@ extension Emitters {
upstream.subscribe(Sub<S>(downstream: subscriber, transformer: transformer))
}

@MainActor

private struct Sub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{
fileprivate init(downstream: Downstream, transformer: @escaping @MainActor (Upstream.Output) -> Output?) {
fileprivate init(downstream: Downstream, transformer: @escaping (Upstream.Output) -> Output?) {
self.downstream = downstream
self.transformer = transformer
}
Expand All @@ -62,7 +61,7 @@ extension Emitters {
}

private let downstream: Downstream
private let transformer: @MainActor (Upstream.Output) -> Output?
private let transformer: (Upstream.Output) -> Output?

}

Expand Down
12 changes: 5 additions & 7 deletions Sources/Emitter/Operators/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import EmitterInterface

extension Emitter {
public func filter(
_ evaluator: @escaping @MainActor (Output) -> Bool
_ evaluator: @escaping (Output) -> Bool
) -> some Emitter<Output> {
Emitters.Filter(upstream: self, evaluator: evaluator)
}
Expand All @@ -14,21 +14,19 @@ extension Emitter {
extension Emitters {
// MARK: - Filter

@MainActor
public struct Filter<Upstream: Emitter, Output: Sendable>: Emitter
where Upstream.Output == Output
{

@MainActor
public init(
upstream: Upstream,
evaluator: @escaping @MainActor (Output) -> Bool
evaluator: @escaping (Output) -> Bool
) where Upstream.Output == Output {
self.evaluator = evaluator
self.upstream = upstream
}

public let evaluator: @MainActor (Output) -> Bool
public let evaluator: (Output) -> Bool
public let upstream: Upstream

public func subscribe<S: Subscriber>(_ subscriber: S)
Expand All @@ -41,7 +39,7 @@ extension Emitters {
private struct Sub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{
fileprivate init(downstream: Downstream, evaluator: @escaping @MainActor (Output) -> Bool) {
fileprivate init(downstream: Downstream, evaluator: @escaping (Output) -> Bool) {
self.downstream = downstream
self.evaluator = evaluator
}
Expand All @@ -64,7 +62,7 @@ extension Emitters {
}

private let downstream: Downstream
private let evaluator: @MainActor (Output)
private let evaluator: (Output)
-> Bool

}
Expand Down
15 changes: 7 additions & 8 deletions Sources/Emitter/Operators/FlatMapLatest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import EmitterInterface

extension Emitter {
public func flatMapLatest<NewOutput: Sendable>(
producer: @escaping @MainActor (Output) -> some Emitter<NewOutput>
producer: @escaping (Output) -> some Emitter<NewOutput>
) -> some Emitter<NewOutput> {
Emitters.FlatMapLatest(upstream: self, producer: producer)
}
Expand All @@ -14,18 +14,17 @@ extension Emitter {
extension Emitters {
// MARK: - FlatMapLatest

@MainActor
public struct FlatMapLatest<Upstream: Emitter, Output: Sendable>: Emitter {

public init(
upstream: Upstream,
producer: @escaping @MainActor (Upstream.Output) -> some Emitter<Output>
producer: @escaping (Upstream.Output) -> some Emitter<Output>
) where Upstream.Output == Upstream.Output {
self.producer = { producer($0).erase() }
self.upstream = upstream
}

public let producer: @MainActor (Upstream.Output) -> AnyEmitter<Output>
public let producer: (Upstream.Output) -> AnyEmitter<Output>
public let upstream: Upstream

public func subscribe<S: Subscriber>(_ subscriber: S)
Expand All @@ -41,15 +40,15 @@ extension Emitters {
)
}

@MainActor

private final class Sub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{

fileprivate init(
downstream: Downstream,
upstream: Upstream,
producer: @escaping @MainActor (Upstream.Output) -> AnyEmitter<Output>
producer: @escaping (Upstream.Output) -> AnyEmitter<Output>
) {
self.downstream = downstream
self.producer = producer
Expand All @@ -71,7 +70,7 @@ extension Emitters {
}
}

@MainActor

private struct InnerSub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{
Expand All @@ -96,7 +95,7 @@ extension Emitters {
}

private let downstream: Downstream
private let producer: @MainActor (Upstream.Output) -> AnyEmitter<Output>
private let producer: (Upstream.Output) -> AnyEmitter<Output>

private let upstream: Upstream
private var current: InnerSub<Downstream>?
Expand Down
13 changes: 6 additions & 7 deletions Sources/Emitter/Operators/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import EmitterInterface

extension Emitter {
public func map<NewOutput: Sendable>(
_ transformer: @escaping @MainActor (Output) -> NewOutput
_ transformer: @escaping (Output) -> NewOutput
) -> some Emitter<NewOutput> {
Emitters.Map(upstream: self, transformer: transformer)
}
Expand All @@ -14,18 +14,17 @@ extension Emitter {
extension Emitters {
// MARK: - Map

@MainActor
public struct Map<Upstream: Emitter, Output: Sendable>: Emitter {

public init(
upstream: Upstream,
transformer: @escaping @MainActor (Upstream.Output) -> Output
transformer: @escaping (Upstream.Output) -> Output
) {
self.transformer = transformer
self.upstream = upstream
}

public let transformer: @MainActor (Upstream.Output) -> Output
public let transformer: (Upstream.Output) -> Output
public let upstream: Upstream

public func subscribe<S: Subscriber>(_ subscriber: S) -> AnyDisposable
Expand All @@ -39,14 +38,14 @@ extension Emitters {
)
}

@MainActor

private struct Sub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{

fileprivate init(
downstream: Downstream,
transformer: @escaping @MainActor (Upstream.Output) -> Output
transformer: @escaping (Upstream.Output) -> Output
) {
self.downstream = downstream
self.transformer = transformer
Expand All @@ -66,7 +65,7 @@ extension Emitters {
}

private let downstream: Downstream
private let transformer: @MainActor (Upstream.Output)
private let transformer: (Upstream.Output)
-> Output

}
Expand Down
3 changes: 1 addition & 2 deletions Sources/Emitter/Operators/Merge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extension Emitter {
extension Emitters {
// MARK: - Merge

@MainActor
public struct Merge<UpstreamA: Emitter, UpstreamB: Emitter, Output: Sendable>: Emitter
where UpstreamA.Output == Output, UpstreamB.Output == Output
{
Expand Down Expand Up @@ -43,7 +42,7 @@ extension Emitters {
)
}

@MainActor

private final class IntermediateSub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{
Expand Down
3 changes: 1 addition & 2 deletions Sources/Emitter/Operators/Print.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ extension Emitter {
extension Emitters {
// MARK: - Print

@MainActor
public struct Print<Upstream: Emitter, Output: Sendable>: Emitter
where Upstream.Output == Output
{
Expand Down Expand Up @@ -96,7 +95,7 @@ extension Emitters {
}
}

@MainActor

private struct Sub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{
Expand Down
3 changes: 1 addition & 2 deletions Sources/Emitter/Operators/RemoveDuplicates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extension Emitter {
extension Emitters {
// MARK: - RemoveDuplicates

@MainActor
public struct RemoveDuplicates<Upstream: Emitter, Output: Sendable>: Emitter where Output: Equatable,
Upstream.Output == Output
{
Expand All @@ -32,7 +31,7 @@ extension Emitters {
upstream.subscribe(Sub<S>(downstream: subscriber))
}

@MainActor

private final class Sub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output, Output: Equatable
{
Expand Down
4 changes: 1 addition & 3 deletions Sources/Emitter/Operators/Union.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ extension Emitter {

extension Emitters {

@MainActor
public struct Union<UpstreamA: Emitter, UpstreamB: Emitter>: Emitter
where UpstreamA.Output: EmitterInterface.Union.Unionable, UpstreamB.Output: EmitterInterface.Union.Unionable
{
Expand Down Expand Up @@ -46,7 +45,7 @@ extension Emitters {
)
}

@MainActor

private final class IntermediateSub<Downstream: Subscriber>: Subscriber
where Downstream.Value == Output
{
Expand Down Expand Up @@ -102,7 +101,6 @@ extension Emitters {

}

@MainActor
private struct Proxy<UpstreamValue, Downstream: Subscriber>: Subscriber where Downstream.Value == Output {

fileprivate init(
Expand Down
1 change: 0 additions & 1 deletion Sources/Emitter/Subjects/PublishSubject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Foundation

// MARK: - PublishSubject

@MainActor
public final class PublishSubject<Value: Sendable>: Emitter, Source {

public init() {}
Expand Down
Loading

0 comments on commit b4596e6

Please sign in to comment.