Hello, I am studying the internal working of corou...
# coroutines
j
Hello, I am studying the internal working of coroutine. I have a simple function like below.
Copy code
fun main() = runBlocking {
 delay(1000)
 println("Bye, world!")
}
If decompile its bytecode into Java, will get the following output:
Copy code
public final class MainKt {
   public static final void main() {
      BuildersKt.runBlocking$default((CoroutineContext)null, (Function2)(new Function2((Continuation)null) {
         int label;

         @Nullable
         public final Object invokeSuspend(@NotNull Object $result) {
            Object var3 = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            switch (this.label) {
               case 0:
                  ResultKt.throwOnFailure($result);
                  this.label = 1;
                  if (DelayKt.delay(1000L, this) == var3) {
                     return var3;
                  }
                  break;
               case 1:
                  ResultKt.throwOnFailure($result);
                  break;
               default:
                  throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }

            String var2 = "Bye, world!";
            System.out.println(var2);
            return Unit.INSTANCE;
         }

         @NotNull
         public final Continuation create(@Nullable Object value, @NotNull Continuation completion) {
            Intrinsics.checkNotNullParameter(completion, "completion");
            Function2 var3 = new <anonymous constructor>(completion);
            return var3;
         }

         public final Object invoke(Object var1, Object var2) {
            return ((<undefinedtype>)this.create(var1, (Continuation)var2)).invokeSuspend(Unit.INSTANCE);
         }
      }), 1, (Object)null);
   }
}
If the function end with
return var3
in
case 0:
in the code above, there should be a code that can enter the function again. I opened runBlocking and delay but couldn’t find it. Where are giving code to continue with label 1 ? (Sorry for the long code snippet)
🤔 2
j
I forgot to check the coroutine repository! thanks!