Here's how to do it using context switches. There ought to be a way to manually pass specific state around to keep that from happening, but probably not since there's no interface to pause something writing to an OutputRange.

auto pipe(T, alias oh)()
{
        import std.concurrency: Generator, yield;
        return new Generator!T({
                        struct OutputRange {
                                void put(T item) {
                                        yield(item);
                                }
                        }
                        oh(OutputRange());
                });
}

Reply via email to