// ĠCopyright Ġ 2 0 0 0 - 2 0 1 8 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . openapi . application . impl Ċ Ċ import Ġcom . intellij . openapi . Disposable Ċ import Ġkotlinx . coroutines . experimental .* Ċ import Ġkotlin . coroutines . experimental . Coroutine Context Ċ import Ġkotlin . coroutines . experimental . Empty Coroutine Context Ċ Ċ /** Ċ Ġ* Ġ@ author Ġel dar Ċ Ġ*/ Ċ interface ĠAsync Execution < E Ġ: ĠAsync Execution < E >> Ġ{ ĊĠ Ġ/** ĊĠĠ Ġ* ĠCreates Ġa Ġnew Ġ[ context ][ Coroutine Context ] Ġto Ġbe Ġused Ġwith Ġthe Ġstandard Ġ[ launch ], Ġ[ async ], Ġ[ with Context ] Ġcoroutine Ġbuild ers . ĊĠĠ Ġ*/ ĊĠ Ġfun Ġcreate Job Context ( context : ĠCor outine Context Ġ= ĠEmpty Coroutine Context , Ġparent : ĠJob ? Ġ= Ġnull ): ĠCor outine Context ĊĊĠ Ġfun Ġwith Constraint ( constraint : ĠContext Constraint ): ĠE ĊĠ Ġfun Ġexpire With ( parent Disposable : ĠDis posable ): ĠE ĊĊĠ Ġinterface ĠContext Constraint Ġ{ ĊĠĠĠ Ġval Ġis Correct Context : ĠBoolean ĊĊĠĠĠ Ġfun Ġto Coroutine Dispatcher ( delegate : ĠCor outine Dispatcher ): ĠCor outine Dispatcher ĊĊĠĠĠ Ġoverride Ġfun ĠtoString (): ĠString ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠImplementation ĠMUST Ġguarantee Ġto Ġexecute Ġa Ġrunnable Ġpassed Ġto Ġ[ schedule ] Ġat Ġsome Ġpoint . ĊĠĠ Ġ* ĠFor Ġdispatch ers Ġthat Ġmay Ġref use Ġto Ġrun Ġthe Ġtask Ġbased Ġon Ġsome Ġcondition ĊĠĠ Ġ* Ġconsider Ġusing Ġ[ Exp irable Context Constraint ] Ġinstead . ĊĠĠ Ġ*/ ĊĠ Ġinterface ĠSimple Context Constraint Ġ: ĠContext Constraint Ġ{ ĊĠĠĠ Ġfun Ġschedule ( run nable : ĠRunnable ) ĊĊĠĠĠ Ġoverride Ġfun Ġto Coroutine Dispatcher ( delegate : ĠCor outine Dispatcher ): ĠCor outine Dispatcher Ġ= ĊĠĠĠĠĠ ĠAsync Execution Support . Simple Constraint Dispatcher ( delegate , Ġthis ) ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠThis Ġclass Ġensures Ġthat Ġa Ġcoroutine Ġcontinuation Ġis Ġinvoked Ġat Ġsome Ġpoint ĊĠĠ Ġ* Ġeven Ġif Ġthe Ġunderlying Ġdispatcher Ġdoesn 't Ġusually Ġrun Ġa Ġtask Ġonce Ġsome Ġ[ Disposable ] Ġis Ġdisposed . ĊĠĠ Ġ* ĊĠĠ Ġ* ĠAt Ġthe Ġvery Ġleast , Ġthe Ġimplementation ĠMUST Ġguarantee Ġto Ġexecute Ġa Ġrunnable Ġpassed Ġto Ġ[ schedule Exp irable ] ĊĠĠ Ġ* Ġif Ġthe Ġcorresponding Ġ[ exp irable ] Ġis Ġstill Ġnot Ġdisposed Ġby Ġthe Ġtime Ġthe Ġdispatcher Ġarrange s Ġthe Ġproper Ġexecution Ġcontext . ĊĠĠ Ġ* ĠIt Ġis ĠOK Ġto Ġexecute Ġit Ġafter Ġthe Ġ[ exp irable ] Ġhas Ġbeen Ġdisposed Ġthough . ĊĠĠ Ġ*/ ĊĠ Ġinterface ĠExp irable Context Constraint Ġ: ĠContext Constraint Ġ{ ĊĠĠĠ Ġval Ġexp irable : ĠDis posable ĊĠĠĠ Ġfun Ġschedule Exp irable ( run nable : ĠRunnable ) ĊĊĠĠĠ Ġoverride Ġfun Ġto Coroutine Dispatcher ( delegate : ĠCor outine Dispatcher ): ĠCor outine Dispatcher Ġ= ĊĠĠĠĠĠ ĠAsync Execution Support . Exp irable Constraint Dispatcher ( delegate , Ġthis ) ĊĠ Ġ} Ċ }