Skip to content

Instantly share code, notes, and snippets.

@shmidt
Created May 25, 2018 17:31
Show Gist options
  • Save shmidt/799dec1ae5266252f4c999c951bdc079 to your computer and use it in GitHub Desktop.
Save shmidt/799dec1ae5266252f4c999c951bdc079 to your computer and use it in GitHub Desktop.
IPAPI+ReactiveKit
//
// IPAPI+ReactiveKit.swift
// Created by Dmitry Shmidt on 5/25/18.
//
import IPAPI
import ReactiveKit
extension Service{
@discardableResult open func fetch(query: String? = nil, fields: [Result.Field]? = nil, language: String? = nil) -> Signal<Service.Result, Service.Error>
{
return Signal { [weak self] observer in
let task = self?.fetch(query: query, fields: fields, language: language, completion: { result, error in
if let error = error as? Service.Error{
observer.failed(error)
}else if let result = result{
observer.next(result)
observer.completed()
}
})
return BlockDisposable {
task?.cancel()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment