@@ -7,8 +7,10 @@ import com.featurevisor.sdk.FeaturevisorError.MissingDatafileOptions
7
7
import com.featurevisor.types.*
8
8
import com.featurevisor.types.EventName.*
9
9
import kotlinx.coroutines.Job
10
+ import kotlinx.coroutines.suspendCancellableCoroutine
10
11
import kotlinx.serialization.decodeFromString
11
12
import kotlinx.serialization.json.Json
13
+ import kotlin.coroutines.resume
12
14
13
15
typealias ConfigureBucketKey = (Feature , Context , BucketKey ) -> BucketKey
14
16
typealias ConfigureBucketValue = (Feature , Context , BucketValue ) -> BucketValue
@@ -122,6 +124,22 @@ class FeaturevisorInstance private constructor(options: InstanceOptions) {
122
124
this .logger?.setLevels(levels)
123
125
}
124
126
127
+ suspend fun onReady (): FeaturevisorInstance {
128
+ return suspendCancellableCoroutine { continuation ->
129
+ if (this .statuses.ready) {
130
+ continuation.resume(this )
131
+ }
132
+
133
+ val cb : (result: Array <out Any >) -> Unit = {
134
+ this .emitter.removeListener(READY )
135
+ continuation.resume(this )
136
+ }
137
+
138
+ this .emitter.addListener(READY ,cb)
139
+ }
140
+ }
141
+
142
+
125
143
fun setDatafile (datafileJSON : String ) {
126
144
val data = datafileJSON.toByteArray(Charsets .UTF_8 )
127
145
try {
0 commit comments