You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that one of the services passed to the "addServices" function is being added twice. I believe there is an oversight in the "addServices" function (if it is important, I was adding a list with only one service):
// To make sure that we are safe from race condition
val totalServices = services.size -1
for (i in0..totalServices) {
servicesToAdd.add(services[i].toGattService())
}
addService(services.last().toGattService())
}
as you can see, you add all the services to the queue and then explicitly add the last one, so it looks like it is added twice. (First time with explicit add, next time with queued add)
I have never used kotlin, but I think it can be solved this way:
overridefunaddServices(services:List<BleService>) {
// To make sure that we are safe from race conditionval totalServices = services.size -1val numOfServicesToAdd =if (servicesToAdd.peek() !=null) totalServices else (totalServices -1)
for (i in0..numOfServicesToAdd) {
servicesToAdd.add(services[i].toGattService())
}
// Start a queue if it isn't startedif (numOfServicesToAdd != totalServices) {
addService(services.last().toGattService())
}
}
I tested this, and this code seems to solve the problem.
If my code is good enough, I can make PR with this change.
Thanks!
The text was updated successfully, but these errors were encountered:
@redssu seems like this is a bug, I was actually planning to leave the race condition handling on flutter side
And just provide a method to add single service, like native
@redssu fixed in new version ( 1.0 ) now we have to add each service one by one, this will improve the race conditions, and proper errors handeling if any service failed to add
Hey,
I noticed that one of the services passed to the "addServices" function is being added twice. I believe there is an oversight in the "addServices" function (if it is important, I was adding a list with only one service):
ble_peripheral/android/src/main/kotlin/com/rohit/ble_peripheral/BlePeripheralPlugin.kt
Lines 97 to 106 in 5f93816
as you can see, you add all the services to the queue and then explicitly add the last one, so it looks like it is added twice. (First time with explicit add, next time with queued add)
I have never used kotlin, but I think it can be solved this way:
I tested this, and this code seems to solve the problem.
If my code is good enough, I can make PR with this change.
Thanks!
The text was updated successfully, but these errors were encountered: