/* Ċ Ġ* ĠCopyright Ġ 2 0 1 6 - 2 0 2 1 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense . Ċ Ġ*/ Ċ Ċ package Ġkotlinx . coroutines . jdk 9 Ċ Ċ import Ġkotlinx . coroutines .* Ċ import Ġkotlinx . coroutines . flow .* Ċ import Ġkotlinx . coroutines . reactive . as Flow Ċ import Ġkotlinx . coroutines . reactive . as Publisher Ġas Ġas Reactive Publisher Ċ import Ġkotlinx . coroutines . reactive . collect Ċ import Ġkotlinx . coroutines . channels .* Ċ import Ġorg . reactiv est ream s .* Ċ import Ġkotlin . coroutines .* Ċ import Ġjava . util . concurrent . Flow Ġas ĠJ Flow Ċ Ċ /** Ċ Ġ* ĠTrans forms Ġthe Ġgiven Ġreactive Ġ[ Flow ĠPublisher ][ J Flow . Publisher ] Ġinto Ġ[ Flow ]. Ċ Ġ* ĠUse Ġthe Ġ[ buffer ] Ġoperator Ġon Ġthe Ġresulting Ġflow Ġto Ġspecify Ġthe Ġsize Ġof Ġthe Ġback - pressure . Ċ Ġ* ĠIn Ġeffect , Ġit Ġspecifies Ġthe Ġvalue Ġof Ġthe Ġsubscription 's Ġ[ request ][ J Flow . Subscription . request ]. Ċ Ġ* ĠThe Ġ[ default Ġbuffer Ġcapacity ][ Channel . BUFFER ED ] Ġfor Ġa Ġsus pending Ġchannel Ġis Ġused Ġby Ġdefault . Ċ Ġ* Ċ Ġ* ĠIf Ġany Ġof Ġthe Ġresulting Ġflow Ġtransformations Ġfails , Ġthe Ġsubscription Ġis Ġimmediately Ġcancelled Ġand Ġall Ġthe Ġin - flight Ċ Ġ* Ġelements Ġare Ġdiscarded . Ċ Ġ*/ Ċ public Ġfun Ġ< T Ġ: ĠAny > ĠJ Flow . Publisher < T >. as Flow (): ĠFlow < T > Ġ= ĊĠĠĠ ĠFlow Adapters . to Publisher ( this ). as Flow () Ċ Ċ /** Ċ Ġ* ĠTrans forms Ġthe Ġgiven Ġflow Ġinto Ġa Ġreactive Ġspecification Ġcompliant Ġ[ Flow ĠPublisher ][ J Flow . Publisher ]. Ċ Ġ* Ċ Ġ* ĠAn Ġoptional Ġ[ context ] Ġcan Ġbe Ġspecified Ġto Ġcontrol Ġthe Ġexecution Ġcontext Ġof Ġcalls Ġto Ġthe Ġ[ Flow ĠSubscriber ][ Subscriber ] Ċ Ġ* Ġmethods . Ċ Ġ* ĠA Ġ[ Coroutine Dispatcher ] Ġcan Ġbe Ġset Ġto Ġconf ine Ġthem Ġto Ġa Ġspecific Ġthread ; Ġvarious Ġ[ Thread Context Element ] Ġcan Ġbe Ġset Ġto Ċ Ġ* Ġinject Ġadditional Ġcontext Ġinto Ġthe Ġcaller Ġthread . ĠBy Ġdefault , Ġthe Ġ[ Un conf ined ][ Dispatch ers . Un conf ined ] Ġdispatcher Ċ Ġ* Ġis Ġused , Ġso Ġcalls Ġare Ġperformed Ġfrom Ġan Ġarbitrary Ġthread . Ċ Ġ*/ Ċ @ Jvm Over loads Ġ// Ġbinary Ġcompatibility Ċ public Ġfun Ġ< T Ġ: ĠAny > ĠFlow < T >. as Publisher ( context : ĠCor outine Context Ġ= ĠEmpty Coroutine Context ): ĠJ Flow . Publisher < T > Ġ= ĊĠĠĠ ĠFlow Adapters . to Flow Publisher ( as Reactive Publisher ( context )) Ċ Ċ /** Ċ Ġ* ĠSub scri bes Ġto Ġthis Ġ[ Flow ĠPublisher ][ J Flow . Publisher ] Ġand Ġperforms Ġthe Ġspecified Ġaction Ġfor Ġeach Ġreceived Ġelement . Ċ Ġ* Ċ Ġ* ĠIf Ġ[ action ] Ġthrows Ġan Ġexception Ġat Ġsome Ġpoint , Ġthe Ġsubscription Ġis Ġcancelled , Ġand Ġthe Ġexception Ġis Ġre throw n Ġfrom Ċ Ġ* Ġ[ collect ]. ĠAlso , Ġif Ġthe Ġpublisher Ġsignals Ġan Ġerror , Ġthat Ġerror Ġis Ġre throw n Ġfrom Ġ[ collect ]. Ċ Ġ*/ Ċ public Ġsuspend Ġinline Ġfun Ġ< T > ĠJ Flow . Publisher < T >. collect ( action : Ġ( T ) Ġ-> ĠUnit ): ĠUnit Ġ= ĊĠĠĠ ĠFlow Adapters . to Publisher ( this ). collect ( action ) Ċ