@@ -69,6 +69,10 @@ internal class OperationRepo(
69
69
private val executeBucket get() =
70
70
if (enqueueIntoBucket == 0 ) 0 else enqueueIntoBucket - 1
71
71
72
+ /* *
73
+ * Perform initialization in background to prevent possible operation point of failures from
74
+ * blocking the creation of OperationRepo.
75
+ */
72
76
init {
73
77
val executorsMap: MutableMap <String , IOperationExecutor > = mutableMapOf ()
74
78
for (executor in executors) {
@@ -78,8 +82,11 @@ internal class OperationRepo(
78
82
}
79
83
this .executorsMap = executorsMap
80
84
81
- for (operation in _operationModelStore .list()) {
82
- internalEnqueue(OperationQueueItem (operation, bucket = enqueueIntoBucket), flush = false , addToStore = false )
85
+ // load operation in a separate thread to avoid halting the main process
86
+ coroutineScope.launch {
87
+ for (operation in _operationModelStore .list().withIndex()) {
88
+ internalEnqueue(OperationQueueItem (operation.value, bucket = enqueueIntoBucket), flush = false , addToStore = false , operation.index)
89
+ }
83
90
}
84
91
}
85
92
@@ -121,12 +128,16 @@ internal class OperationRepo(
121
128
queueItem : OperationQueueItem ,
122
129
flush : Boolean ,
123
130
addToStore : Boolean ,
131
+ index : Int = -1,
124
132
) {
125
133
synchronized(queue) {
126
- queue.add(queueItem)
127
- if (addToStore) {
128
- _operationModelStore .add(queueItem.operation)
129
- }
134
+ if (index >= 0 )
135
+ queue.add(index, queueItem)
136
+ else
137
+ queue.add(queueItem)
138
+ }
139
+ if (addToStore) {
140
+ _operationModelStore .add(queueItem.operation)
130
141
}
131
142
132
143
waiter.wake(LoopWaiterMessage (flush, 0 ))
0 commit comments