Besonderhede van voorbeeld: 6119691880418702009

Metadata

Author: WikiMatrix

Data

Czech[cs]
Nicméně je stále možné implementovat koprogramy za pomocí více generátorů s vrchní rozhodující funkcí, která předává kontrolu explicitně svým generátorům identifikovatelným pomocí tokenů, které jsou z nich předány zpět: var q := new queue generator produce loop while q is not full create some new items add the items to q yield consume generator consume loop while q is not empty remove some items from q use the items yield produce subroutine dispatcher var d := new dictionary(generator → iterator) d := start produce d := start consume var current := produce loop current := next d Mnoho implementací koprogramů pro jazyky s podporou generátorů, avšak bez nativních koprogramů (e.g.
English[en]
However, it is still possible to implement coroutines on top of a generator facility, with the aid of a top-level dispatcher routine (a trampoline, essentially) that passes control explicitly to child generators identified by tokens passed back from the generators: var q := new queue generator produce loop while q is not full create some new items add the items to q yield consume generator consume loop while q is not empty remove some items from q use the items yield produce subroutine dispatcher var d := new dictionary(generator → iterator) d := start produce d := start consume var current := produce loop current := next d A number of implementations of coroutines for languages with generator support but no native coroutines (e.g. Python before 2.5) use this or a similar model.

History

Your action: