https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Alex Edwards

10/22/2021, 8:22 PM
Can i wrap a default value in a deffered type?
Copy code
MyClass(options: Deferred<Map<String, String>> = emptyMap()) {
  // This constructor doesn't actually compile, its an example of what i would like to achieve 
  //some stuff
}
The map passed in here is ultimately wrapped in a promise. currently i have a js snippet that essentially does
Copy code
options.then { new MyClass(it) }
ideally i would like to move this into my kotlin code but I would still like to handle
MyClass()
is there a way i can do this?
r

Richard Gomez

10/22/2021, 8:32 PM
Perhaps with
CompletableDeferred
? https://github.com/Kotlin/kotlinx.coroutines/blob/5eca49cfcb25acefaf10ec9b997de537c653b47e/kotlinx-coroutines-core/common/src/CompletableDeferred.kt#L70-L74
Copy code
MyClass(options: Deferred<Map<String, String>> = CompletableDeferred(emptyMap())) {
}
Cant say whether it's 'idiomatic'.
👀 1
2 Views