Skip to content

Commit 25b6dda

Browse files
committed
[Feat] Define helpers when the publisher is Void and Future is used
1 parent 14a8d99 commit 25b6dda

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// Publisher+FutureHelpers.swift
3+
//
4+
//
5+
// Created by 양승현 on 5/8/24.
6+
//
7+
8+
import Foundation
9+
10+
#if canImport(Combine) && os(iOS) && swift(>=5.0)
11+
import Combine
12+
13+
public extension Publisher
14+
where Output == Void, Failure == FirestoreServiceError {
15+
func sink(promise: @escaping Future<Output, Error>.Promise) -> AnyCancellable {
16+
return sink { completion in
17+
if case .failure(let error) = completion {
18+
promise(.failure(error))
19+
}
20+
} receiveValue: { _ in
21+
promise(.success(()))
22+
}
23+
}
24+
25+
func sink(promise: @escaping Future<Output, Failure>.Promise) -> AnyCancellable {
26+
return sink { completion in
27+
if case .failure(let error) = completion {
28+
promise(.failure(error))
29+
}
30+
} receiveValue: { _ in
31+
promise(.success(()))
32+
}
33+
}
34+
}
35+
36+
public extension Publisher
37+
where Output == Void, Failure == Error {
38+
func sink(promise: @escaping Future<Output, Failure>.Promise) -> AnyCancellable {
39+
return sink { completion in
40+
if case .failure(let error) = completion {
41+
promise(.failure(error))
42+
}
43+
} receiveValue: { _ in
44+
promise(.success(()))
45+
}
46+
}
47+
}
48+
#endif

0 commit comments

Comments
 (0)