asad.awadia
01/02/2018, 1:11 PMlouiscad
01/02/2018, 1:16 PMasad.awadia
01/02/2018, 1:18 PMcan be used to await events like the code was blocking a thread, but without blocking a thread
<--- this is exactly what I thought they provided too - do u have any examples?hiperbou
01/02/2018, 1:20 PMlouiscad
01/02/2018, 1:22 PMawaitInternetConnection()
in a coroutine (a suspend block), and your code would go past the awaitInternetConnection()
call only when the internet connection is there, that is, when the method resumes from suspension, and would do this, without blocking any thread or locking up precious ressourcesGate
class: https://github.com/Beepiz/BleGattCoroutines/blob/bdb7b82b2b46f813633ae471122c19754aab939c/blegattcoroutines/src/main/java/com/beepiz/bluetooth/gattcoroutines/experimental/Gate.ktasad.awadia
01/02/2018, 1:25 PMawaitInternetConnection()
a suspend function or is it of the form fun awaitInternatConnection() = launch {//code}
runBlocking
it will block the thread which voids the whole point correct?louiscad
01/02/2018, 1:26 PMawaitInternetConnection()
is a suspend functionasad.awadia
01/02/2018, 1:26 PMlouiscad
01/02/2018, 1:27 PMawaitInternetConnection()
function?asad.awadia
01/02/2018, 1:29 PMlouiscad
01/02/2018, 1:32 PMCommonPool
most of the time. Blocking I/O should be done on a thread pool properly sized for the running environment (like you'd do in Java), but for prototyping, having a global (top-level) val IO = CommonPool
is okay as long as it doesn't locks up CPU-bound computations that are normally the stuff CommonPool
is made for.CommonPool
, IO
or other coroutine contexts as arguments for async(...) { ... }
and launch(...) { ... }
BroadcastChannel
consumed by various parts of your program, or feed it to a class like the Gate
class I showed you earlier, that could the be used to write a suspending awaitInternetConnection()
suspend function