https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

androidexpertmanish

06/24/2021, 4:32 AM
Hi I am new to coroutines. I am having an issue with delay function. I have a foreground service in which I am starting bluetooth scanning then delaying for 20 seconds and then calling stopScan. Now, scan result is start coming 20 seconds late, is it because of delay?
code snippet example is here
message has been deleted
g

gildor

06/24/2021, 4:52 AM
Not sure that it directly related to coroutines, it more like an implementation detail of this mManager (it’s really not clear what kind class it is, it doesn’t look as BluetoothLeScanner API)
a

androidexpertmanish

06/24/2021, 4:56 AM
Its a wrapper written for doing different BT operation on device. startScan function is using core BluetoothLeScanner API internally to do scanning and then onScanResult() is receiving devices data which came into scan list. My concern is, delay of 20 seconds shouldn’t affect scanning process as I can see as soon I call start scan function, scanning is started. is delay function stopping main thread?
g

gildor

06/24/2021, 5:01 AM
No, delay function is not stopping main thread
it looks like some other problem in your wrapper
maybe it waits until stopScan() is called
r

reline

06/24/2021, 3:40 PM
Definitely an implementation detail, depending on your scan settings or scan mode, the scan results might not be delivered until scanning is finished, hence the "delay" you are seeing. I recommend using the default scan settings and you should see the expected behavior.
a

androidexpertmanish

07/03/2021, 8:11 AM
@gildor and @reline thanks a lot for clearing doing, problem was in BT manager class itself.
7 Views