774ed51e1b
* NSCv3 initial work * Allow only 1 NSC * read sgv * NSv3: Read Bolus, Carbs * NSCv3: more work * fix build * loading working * work on TT * TT working * TBR processing * EPS working * PS Sync * Process entries at once. Share code v1,v3 * BolusCalculatorWizard working * TherapyEvent working * process bg at once * improve sync * sdk -> ns-sdk * handle status per version * OffileEvents working * EB working * RemoteDeviceStatus * fix build * cleanup
28 lines
971 B
Kotlin
28 lines
971 B
Kotlin
package info.nightscout.sdk
|
|
|
|
import info.nightscout.sdk.interfaces.NSAndroidCallbackClient
|
|
import info.nightscout.sdk.interfaces.NSAndroidClient
|
|
import info.nightscout.sdk.localmodel.Status
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.SupervisorJob
|
|
import kotlinx.coroutines.launch
|
|
|
|
class NSAndroidCallbackClientImpl(private val client: NSAndroidClient) :
|
|
NSAndroidCallbackClient {
|
|
|
|
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
|
|
|
@Suppress("TooGenericExceptionCaught")
|
|
override fun getStatus(callback: NSAndroidCallbackClient.NSCallback<Status>): NSAndroidCallbackClient.NSCancellable =
|
|
NSAndroidCallbackClient.NSJobCancellable(
|
|
scope.launch {
|
|
try {
|
|
callback.onSuccess(client.getStatus())
|
|
} catch (e: Exception) {
|
|
callback.onFailure(e)
|
|
}
|
|
}
|
|
)
|
|
}
|