can you guys advise what’s an idiomatic way of han...
# coroutines
a
can you guys advise what’s an idiomatic way of handling a suspending initialization? Let’s say my class exposes a
search
function and this function depends on a series of initialization steps that the instance has to perform before being able to actually search and return results. How would you handle this using coroutines? Would you have an
initialize
function that returns a
Job
or would you simply mark
search
as
suspend
and “hide” the suspension as an implementation detail waiting internally for the initialization job to complete? Or would you tackle this issue in a completely different way?
w
I’d probably have the initialization steps return
Deferred
and then if
search
is called, make sure your search function
await
on those steps
👍 3
d
Or you could wrap the work in an
actor
and pass the actor the return
Channel
to send the results too.
d
Would probably use one property to hold a
Job
instance and join it