mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
incorporate androidlib
This commit is contained in:
parent
20cf3f0825
commit
5eb5cd1421
63 changed files with 1451 additions and 108 deletions
|
|
@ -0,0 +1,30 @@
|
|||
package com.geeksville.mesh.concurrent
|
||||
|
||||
import com.geeksville.mesh.android.Logging
|
||||
|
||||
|
||||
/**
|
||||
* Sometimes when starting services we face situations where messages come in that require computation
|
||||
* but we can't do that computation yet because we are still waiting for some long running init to
|
||||
* complete.
|
||||
*
|
||||
* This class lets you queue up closures to run at a later date and later on you can call run() to
|
||||
* run all the previously queued work.
|
||||
*/
|
||||
class DeferredExecution : Logging {
|
||||
private val queue = mutableListOf<() -> Unit>()
|
||||
|
||||
/// Queue some new work
|
||||
fun add(fn: () -> Unit) {
|
||||
queue.add(fn)
|
||||
}
|
||||
|
||||
/// run all work in the queue and clear it to be ready to accept new work
|
||||
fun run() {
|
||||
debug("Running deferred execution numjobs=${queue.size}")
|
||||
queue.forEach {
|
||||
it()
|
||||
}
|
||||
queue.clear()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue