AndroidAPS/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidCallbackClientImpl.kt
Milos Kozak 774ed51e1b
NSClient v3 initial work, NS v1 improvements
* 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
2022-11-08 09:23:46 +01:00

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)
}
}
)
}