Office Hours Transcript: 2021-05-06

Jan joined

Hi, Mark

Is there a difference in context or dispatcher when run code directly inside a launch body versus launch body calling a suspend fun?

Example:
Inside a view model:
Version 1:

suspend fun retryConnects(ntries: Int) {
        connectJob = async { bluetoothInteractor.connectToDevice(device) }
        withTimeout(WAIT_TIME) {
            val connected = connectJob?.await() ?: false
        }
   }
   
   
fun onContinueClicked() {
    launch {
        retryConnects(4)
        }
    }
    
    
    
versus:

Version 2:

fun onContinueClicked() {
    launch {
        -->??? same dispatcher/context/scope as when these lines run from retryConnects ???
        connectJob = async { bluetoothInteractor.connectToDevice(device) }
        withTimeout(WAIT_TIME) {
            val connected = connectJob?.await() ?: false
        }
        }
    }

I ask because app is running better today when yesterday it kept getting the
Gatt 133 bluetooth connection error.

The above was the change I made but probably just a coincidence. Android bluetooth stack seems unstable.

Is there a difference in context or dispatcher when run code directly inside a launch body versus launch body calling a suspend fun?

No. Your coroutine could suspend at the point of any suspend function call (whether it is a function that you wrote or one from a library). But the scope and dispatcher remain the same.

Because I’m running it in viewmodel, would it be using main dispatcher?

The default dispatcher is based on the CoroutineScope and how it is set up. viewModelScope uses Dispatchers.Main.immediate as the default dispatcher.

And, you can pass whatever dispatcher you want to launch(), such as launch(Dispatchers.IO)

Ok. Thanks for clearing that up.

Jan left

trocchietto_ivano joined

hallo w0rl1

hello, Ivano! how can I help you today?

hi mark this hack chat is fantastic

and I have an out of box question today

go right ahead!

basically there is a sw called zoom notes int he app store that allow to zoom infinitely a canvas to add notes nested into notes, images etc. https://apps.apple.com/us/app/zoomnotes/id462234530

the funny thing is that I was using it while I was having a mini ipad 2 with really low hardware/ram specifications

and I could zoom indefinetely

in the Android world there is the great app to draw called infinitive design

that is fantastic and also allow to zoom a lot

how is possible to zoom with such extent without having an out of memory Ex?

Well, the details may vary, but in the end, your question is pretty much the same as "how can we have a scrolling list with tens of thousands of items in it without running out of memory?"

The answer is: you cheat. 😁

you mean i recycle

right

this is an hack reply for an hack chat !

it’s a popular Android library for zooming into large images, including ones far too big to hold in memory

it basically loads a downscaled version of the image, then loads portions as needed as the user zooms

Google Maps does the same sort of thing with map tiles

this is so fascinating

https://github.com/peterLaurence/MapCompose offers a Jetpack Compose version of the same sort of map tile management

and do you know if these software use services, or store the images in other activities, canvas

in general, it needs to be loaded "on the fly" for the very memory issues that you cited

so, with Google Maps and MapCompose, as the user pans and zooms, it loads new tiles

and is not recreated a math fourier transformation

well, some things might be able to algorithmically handle that sort of approach

I have not dealt with anything like that personally

I need to study the math beyond that, I have been always fascinated by our matrix work to scale images

well perfect thanks

you untangled the mystery #root access!

I go to sleep thank you very much I am going to have a deeper look tomorrow

you’re welcome, and pleasant dreams!

trocchietto_ivano left