Is it possible to make the equivalent of an immedi...
# coroutines
s
Is it possible to make the equivalent of an immediate executor but a
CoroutineContext
without depending on
coroutines-core
but only on what can be found in
std-lib
?
b
Isn't CoroutineContext defined by coroutines-core?
What do you mean by an "immediate executor"?
d
You have to implement
ContinuationInterceptor
and put it in the context
CoroutineContext
can be found in the std lib, it is not part of kotlinx library.
s
@bdawg.io I need an executor that executes the code on immediately on the current thread. Something like Guava directExecutor.
Copy code
final class DirectExecutor implements Executor {
   public void execute(Runnable r) {
     r.run();
   }
 }
d
Then I suggest
override fun interceptContinuation(cont: Continuation<*>) = cont
Excuse me if that's not the signature
s
Alright thanks, I’ll look into that 🙂 What are you supposed to do with those keys?
d
Look at documentation of
CoroutineContext
s
😅 Thanks!
The key that you need is here
s
Could you help clarify how returning the
continuation
like so
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = continuation
executes it on the immediate thread?
The interception they refer to in the docs, does that mean intercept to coroutine to execute it on some other context? Thus intercepting all resumptions to that new context as well.
d
The intercepted continuation optionally wraps the original, scheduling it to be resumed on a thread or in some event loop
s
Alright, thanks a lot for the help 🙂