Olekss
01/27/2018, 9:54 PMPaul Woitaschek
01/27/2018, 9:58 PMUnconfined
in tests generally seems to be a good ideaFelix
01/28/2018, 12:10 AMnikolaymetchev
01/28/2018, 8:04 PMjava.security.AccessControlException: access denied ("java.util.PropertyPermission" "os.name" "read")
. We were able to mitigate some of them by wrapping certain calls in AccessController.doPrivileged(...)
, but that only pushed the problem furthe down and eventually we got NullPointerExceptions deep in our swing code java.lang.NullPointerException
at javax.swing.SizeRequirements.calculateAlignedPositions(Unknown Source)
at javax.swing.BoxLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at java.awt.CardLayout.first(Unknown Source)
Once we reverted the code back to using SwingWorker all those security exceptions disappeared. We are using Oracle Java 8 build 162 with kotlin 1.2.21 and coroutines swing version 0.22. Please let me know if this is a known problem and if I should bother trying to create a bug report for Jetbrains. Many thanks.Olekss
01/29/2018, 7:22 PMdave08
01/30/2018, 3:52 AMpublic actual inline fun CoroutineExceptionHandler(crossinline handler: (CoroutineContext, Throwable) -> Unit): CoroutineExceptionHandler =
object: AbstractCoroutineContextElement(CoroutineExceptionHandler), CoroutineExceptionHandler {
override fun handleException(context: CoroutineContext, exception: Throwable) =
handler.invoke(context, exception)
}
I think you were missing the CoroutineContext's element key companion object, which is what replaces your context with the default one in the lib, but the above should do the trick...dstarcev
01/30/2018, 1:20 PMwithoutclass
01/30/2018, 4:16 PMlaunch {
whileSelect {
channel.onReceive {
when (it) {
// do stuff
}
}
}
}
nerses
01/31/2018, 4:22 PMnerses
01/31/2018, 4:27 PMjohannes.lagos
01/31/2018, 9:03 PMsuspend fun requestSomething() {
return suspendableCoroutine{cont->
api.makeACall(object: Response{
fun onResponse(response: Response){
cont.resume(response)
}
fun onError(error: Error) {
cont.resumeWithException(Throwable(error.message)
}
})
}
}
And where I trigger the coroutine:
fun aMethod(){
launch(Android){
try{
requestSomething()
}catch(e: Exception) {
Timber.d("something went wrong")
}
}
}
r4zzz4k
01/31/2018, 9:11 PMsuspendableCoroutine
is a low-level primitive, so it's reasonable to replace it with CompletableDeferred
. Someone should correct me if I'm wrong, or maybe provide details on why.bitkid
02/01/2018, 12:24 PMelizarov
02/01/2018, 2:57 PMdstarcev
02/01/2018, 3:37 PMbj0
02/01/2018, 6:20 PMwithContext(UI) { }
was equivalent to async(UI) { }.await()
, but I am having serious problems with the latter, was that not the case?elizarov
02/02/2018, 3:40 PMgroostav
02/02/2018, 9:25 PMjavax.concurrent.Task
?dave08
02/04/2018, 3:47 AMnil2l
02/05/2018, 11:14 AMdave08
02/05/2018, 4:36 PMlaunch(UI)
is not reached at all after it was run? And the screen in Android device goes black... I tried putting logs there, reducing it to doing almost nothing (only Log
...)... the screen just blanks outelizarov
02/07/2018, 6:46 PMkotlinx.coroutines
when Kotlin 1.2.30 is out. The plan is to have isActive
extension on CoroutineContext
, so that you can use coroutineContext.isActive
. The open question is whether CoroutineScope
shall be completely deprecated and slated for removal or should we leave isActive
"shortcut" in the CoroutineScope
?nerses
02/08/2018, 1:40 PMfun populate(hotels: List<Hotel>) {
val context = newFixedThreadPoolContext(threadpoolCoreSize, "thread-geo")
context.use { c ->
val jobs = hotels.map { hotel ->
launch(c) {
repo.suspendableFun()
}
}
runBlocking(c) {
jobs.forEach({ it.join() })
}
}
}
and
@Test(expectedExceptions = [RuntimeException::class])
fun `populate should throw exceptionIn`() = runBlocking {
//and
given(repo.suspendableFun()).willThrow(RuntimeException(""))
//when
victim.populate(hotelList())
//then
//The exception is thrown
}
bazted
02/09/2018, 11:16 AMonComplete
like listener for ReceiveChannel. for now I have fun <T> ReceiveChannel<T>.onComplete(action: suspend () -> Unit): ReceiveChannel<T> {
launch(Unconfined) {
consumeEach { }
action()
}
return this
}
gaetan
02/09/2018, 1:31 PMjimn
02/09/2018, 9:59 PMlouiscad
02/10/2018, 3:21 PMonCreate(…)
would be a suspend fun
so I can right away use withContext(IO)
for things like SharedPreferences access, but should I? Should I use coroutines everywhere so whenever I need to access even small things in storage that may be cached in memory, I can just do it in a non UI thread coroutineContext and suspend when I can?louiscad
02/10/2018, 4:38 PMonResume()
coroutine when onPause()
is called.mansonheart
02/10/2018, 6:46 PMdelay()
work?
A comment in source code (method scheduleResumeAfterDelay
) says: This implementation is supposed to use dispatcher's native ability for scheduled execution in its thread(s).
It means that the method interacts with the thread scheduler to put the current thread into a wait state for the required interval? (like Thread.sleep() https://www.javamex.com/tutorials/threads/sleep.shtml)
Or what kind of native ability are we talking about?louiscad
02/11/2018, 10:33 AMwithContext
handles cancellation before and after running its lambda?louiscad
02/11/2018, 10:33 AMwithContext
handles cancellation before and after running its lambda?Jonathan
02/13/2018, 4:56 PMBy default, the coroutine is immediately scheduled for execution and can be cancelled while it is waiting to be executed and it can be cancelled while the result is scheduled to be processed by the invoker contextmy understanding is the correct answer to your question is "before and after"
louiscad
02/13/2018, 6:15 PMwithContext
doc (which I would have shamefully overlooked), or somewhere else (in this case, could you link it?)?Jonathan
02/13/2018, 8:57 PMwithContext
doc. https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/with-context.html