ron
01/14/2017, 6:34 AMron
01/14/2017, 6:34 AMelizarov
01/14/2017, 6:37 AMasyncRun { ... }
coroutine builder in kotlinx.coroutines
to "fire-and-forget" new coroutine, but it has different threading semantics to runAsync
and I'd like to avoid confusion between the two by either picking a different name of adjusting its semantics.ron
01/14/2017, 6:37 AMasyncRun
would not report back at the end of the work?elizarov
01/14/2017, 6:38 AMfork
. But that has far-reaching implications is that every coroutine builder will have to be renamed to something else (right now they all like asyncXXX
, so you have a hint that some asynchronous activity is going to be started)ron
01/14/2017, 6:39 AMelizarov
01/14/2017, 6:39 AMasyncRun
would not report. asyncValue
will return an AsyncValue
(a non-blocking future) and if you like futures you could do asyncFuture
, or if you like Rx you could do asyncObservable
. Different coroutine builders have different result types.ron
01/14/2017, 6:40 AMasyncRun
does not make clear that it does not report back like asyncValue
doesron
01/14/2017, 6:41 AMasyncVoid
?elizarov
01/14/2017, 6:41 AMasyncFuture
and then ignore its result is not going to work, as any exception inside that coroutine is going to be stored in that future and if you did not use your future, then you'd never know it had crashed (very hard to debug!)ron
01/14/2017, 6:41 AMron
01/14/2017, 6:41 AMasyncForget
?elizarov
01/14/2017, 6:42 AMgo
(it is a keyword in Go language that does exactly that -- fire and forget new coroutine)ron
01/14/2017, 6:42 AMasync { do something} ui { do something with the result }
is importantelizarov
01/14/2017, 6:43 AMelizarov
01/14/2017, 6:43 AMron
01/14/2017, 6:44 AMasync
in it to make clear it is a different threadelizarov
01/14/2017, 6:44 AMfun makeRestCall(...)
you have suspend fun makeRestCall(...)
that does not block a thread. Then, instead of runAsync { makeRestCall(...) } ui { result -> doSomethingWith(result) }
you could just do asyncRun { doSomethingWith(makeRestCall(...)) }
ron
01/14/2017, 6:45 AMasync
?ron
01/14/2017, 6:45 AMelizarov
01/14/2017, 6:45 AMasync
, so we'd rather leave this name unused in the general libraryron
01/14/2017, 6:45 AMfun <T> runAsync(status: TaskStatus? = find<TaskStatus>(scope), func: FXTask<*>.() -> T) = task(status, func)
ron
01/14/2017, 6:46 AMfun <T> task(taskStatus: TaskStatus? = null, func: FXTask<*>.() -> T): Task<T> = FXTask(taskStatus, func = func).apply {
setOnFailed({ Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), exception) })
Thread(this).start()
}
ron
01/14/2017, 6:47 AMelizarov
01/14/2017, 6:48 AMasyncRun
(or how else we name it) is that in UI applications it schedules all continuation onto UI thread by-default. So your code in runAsync { ... }
is asynchronous (does not block a thread), but still runs inside an even-dispatch thread.ron
01/14/2017, 6:48 AMbackground
somewhere in 1.4.7 I yhinkelizarov
01/14/2017, 6:48 AMasyncRun(myComputePool) { ... }
ron
01/14/2017, 6:49 AMsuspend
is a new keyword then?elizarov
01/14/2017, 6:49 AMsuspend
is a new soft-keywordron
01/14/2017, 6:52 AM