aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp/Shared/FlowCollector.swift
blob: 1613f2083d2c75cb68d7a52bc6e373625f0e8535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
//  FlowCollector.swift
//  iosApp
//
//  Created by Iván on 23/01/22.
//  Copyright © 2022 orgName. All rights reserved.
//

import Foundation
import shared

// Source: https://stackoverflow.com/66030092
class Collector<T>: Kotlinx_coroutines_coreFlowCollector {
    
    let callback: (T) -> Void
    
    init(callback: @escaping (T) -> Void) {
        self.callback = callback
    }
    
    func emit(value: Any?, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
        callback(value as! T)
        
        completionHandler(KotlinUnit(), nil)
    }
}