ok :slightly_smiling_face: I faced with the proble...
# reaktive
l
ok 🙂 I faced with the problem, how can I call extension methods from swift. I know it isn’t good, but right now I need it. I saw an issue about it on github, but I haven’t found a solution.
a
The main problem here is that generics are not exported to Swift for interfaces and functions, only for classes. Currently Reaktive provides wrapper classes for all the stream types. You can write something like this:
Copy code
class SharedDataSource {
    fun load(): SingleWrapper<String> =
        singleFromFunction { 
            // A long running operation
            "A result"
        }
            .subscribeOn(ioScheduler)
            .observeOn(mainScheduler)
            .wrap()
}
After that you will be able to subscribe like this:
Copy code
let dataSource = SharedDataSource()

let disposable = dataSource
    .load()
    .subscribe(isThreadLocal: false, onSubscribe: nil, onError: nil) { (value: NSString) in print(value) }
       
    // At some point later
    disposable.dispose()
But
subscribe
is the only method available in the provided wrappers. If you need additional operators you can extend the wrapper with your custom class and add whatever you want there.
l
oh great, my thx. I did it without
wrap
function, but I have a trouble with mutation state. thx for the response.
Right now I have a stupid question, onError callback is called on a thread which was set in observeOn operator?
a
Correct, if you have one