package Ġcom . ap ol log raph ql . apollo 3 . network Ċ Ċ import Ġkotlinx . c interop . CO pa que Pointer Ċ import Ġkotlinx . c interop . Stable Ref Ċ import Ġkotlinx . c interop . as Stable Ref Ċ import Ġkotlinx . c interop . static C Function Ċ import Ġplatform . Foundation . N ST hread Ċ import Ġplatform . darwin . dispatch _ async _ f Ċ import Ġplatform . darwin . dispatch _ get _ main _ queue Ċ import Ġkotlin . coroutines . Continuation Ċ import Ġkotlin . coroutines . resume Ċ import Ġkotlin . native . concurrent . freeze Ċ Ċ /** Ċ Ġ* ĠA Ġtrick Ġto Ġsupport Ġcor outines Ġwithout Ġrelying Ġon Ġ` coroutines - mt ` ĠIt Ġmakes Ġthe Ġassumption Ċ Ġ* Ġthat Ġthe ĠApple Ġcor outines Ġrun Ġin Ġthe Ġmain Ġthread Ġand Ġ" tunnel s " Ġthe Ġcontinuation Ġthrough Ċ Ġ* Ġan Ġopaque Pointer Ġwithout Ġfree zing Ġso Ġthat Ġit Ġcan Ġbe Ġres umed Ġlater Ġon Ċ Ġ* Ċ Ġ* Ġ@ param Ġcontinuation Ptr Ġa Ġ[ Continuation ] Ġopaque Ġpointer Ġobtained Ġwith Ġ` Stable Ref . create ( continu ation ). as CP o inter ()` Ċ Ġ*/ Ċ internal Ġfun Ġ< R > ĠResult < R >. dispatch On Main ( continu ation Ptr : ĠCO pa que Pointer ) Ġ{ ĊĠ Ġif Ġ( N ST hread . is MainThread ()) Ġ{ ĊĠĠĠ Ġdispatch ( continu ation Ptr ) ĊĠ Ġ} Ġelse Ġ{ ĊĠĠĠ Ġval Ġcontinuation With Result Ref Ġ= ĠSt able Ref . create (( continu ation Ptr Ġto Ġthis ). freeze ()) ĊĊĠĠĠ Ġdispatch _ async _ f ( ĊĠĠĠĠĠĠĠ Ġqueue Ġ= Ġdispatch _ get _ main _ queue (), ĊĠĠĠĠĠĠĠ Ġcontext Ġ= Ġcontinuation With Result Ref . as CP o inter (), ĊĠĠĠĠĠĠĠ Ġwork Ġ= Ġstatic C Function Ġ{ Ġptr Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġval Ġcontinuation With Result Ref 2 Ġ= Ġptr !!. as Stable Ref < Pair < CO pa que Pointer , ĠResult < R >> >() ĊĠĠĠĠĠĠĠĠĠ Ġval Ġ( continu ation Ptr 2 , Ġresult ) Ġ= Ġcontinuation With Result Ref 2 . get () ĊĠĠĠĠĠĠĠĠĠ Ġcontinuation With Result Ref 2 . dispose () ĊĊĠĠĠĠĠĠĠĠĠ Ġresult . dispatch ( continu ation Ptr 2 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĠ Ġ} Ċ } Ċ Ċ private Ġfun Ġ< R > ĠResult < R >. dispatch ( continu ation Ptr : ĠCO pa que Pointer ) Ġ{ ĊĠ Ġval Ġcontinuation Ref Ġ= Ġcontinuation Ptr . as Stable Ref < Continuation < Result < R >> >() ĊĠ Ġval Ġcontinuation Ġ= Ġcontinuation Ref . get () ĊĠ Ġcontinuation Ref . dispose () ĊĊĠ Ġcontinuation . resume ( this ) Ċ } Ċ