dave08
05/01/2018, 4:43 AMfun ReceiveChannel. toDeferred() = async { single() }
, @spierce7 maybe, but probably not such good practice in coroutines to do such a thing though...spierce7
05/01/2018, 1:36 PMdave08
05/01/2018, 1:41 PMspierce7
05/01/2018, 1:46 PMclass AuthWorkflow : AbstractWorkflow<Unit, Unit>() {
protected val resultChannel = Channel<Unit>()
override fun start(input: Unit): Deferred<Unit> {
return resultChannel.toDeferred()
}
override fun abort() {
}
fun finish() {
resultChannel.offer(Unit)
}
}
dave08
05/01/2018, 1:57 PMstart
into a suspend fun
and call single()
or receive()
. The Channel is fine, the deferred might not be necessary...spierce7
05/01/2018, 2:15 PMstart
and receive a deferred back. The deferred won't have a result until the AuthWorkflow is complete, at which point it will return, return and the person who called start() will then be notifieddave08
05/01/2018, 3:18 PMspierce7
05/01/2018, 3:20 PMdave08
05/01/2018, 3:21 PMawait()
the result.. then you call that in your suspend function and until the result is not there, it won't returnspierce7
05/01/2018, 6:01 PMstart
function is called when the user first goes to the auth / login page, and the Deferred
that will return from it will complete when the user successfully logs indave08
05/01/2018, 6:11 PMsuspend fun login()
function...spierce7
05/01/2018, 6:17 PMdave08
05/01/2018, 6:18 PMlogin()
as if it would return right away and let it suspend until the result comes in, the next steps will be stored in a continuation until the result arrives, and then the code continuesspierce7
05/01/2018, 6:18 PMdave08
05/01/2018, 6:19 PMspierce7
05/01/2018, 6:19 PMdave08
05/01/2018, 6:20 PMspierce7
05/01/2018, 6:20 PMstart
returns a Deferred
, and that Deferred
, won't complete until after the user has successfully logged indave08
05/01/2018, 6:21 PMspierce7
05/01/2018, 6:22 PMdave08
05/01/2018, 6:23 PMCompletableDeferred
. But you need to call it from some callback or something...suspend fun
spierce7
05/01/2018, 6:26 PMCompletableDeferred
is exactly what I needdave08
05/01/2018, 6:26 PMasync(MyThreadPool) { ... }
and you get a Deferred as a resultspierce7
05/01/2018, 6:26 PMdave08
05/01/2018, 6:27 PM