What’s the convention for initializing a `var` of ...
# coroutines
t
What’s the convention for initializing a
var
of type
Job
to some “no-op” value to avoid having a nullable type?
The best I could come up with is
var job = scope.launch {}
j
null
seems a pretty good candidate though. You can also just call
Job()
to get an active-yet-detached instance.
t
Would you say it’s still a good candidate in the context of a Compose function where I lose out on smart casting and have to copy it?
Copy code
var inactiveTimeout: Job? by rememberRetained { mutableStateOf(null) }

...

//"Smart cast to 'Job' is impossible.."
if (inactiveTimeout != null && !inactiveTimeout.isActive) {
...
Maybe it’s just my aversion to safe calls I need to get over. Seen too many apps with them littered all over.
j
Seems like it could go either way based on your preference then, yeah.
We need Swift's if-let bindings
☝🏻 1
☝️ 6
e
Copy code
if (inactiveTimeout?.isActive == false) {