Hello,

I'm trying to understand how fibers/tasks work in vibe.d.

module app;

import std.stdio;
import vibe.core.core;
import core.time;

void main()
{
    runTask({
        foreach(immutable i; 0..5)
        {
            writeln(i);
            sleep(dur!"msecs"(100));
        }
    });

    runTask({
        foreach(immutable i; 5..10)
        {
            writeln(i);
            sleep(dur!"msecs"(1000));
        }
    });

    runEventLoop();
}

This source code produces

0
5
6
7
8
9
1
2
3
4

Which makes sense. However, when adding a yield like so:

module app;

import std.stdio;
import vibe.core.core;
import core.time;

void main()
{
    runTask({
        foreach(immutable i; 0..5)
        {
            writeln(i);
            sleep(dur!"msecs"(100));
        }
    });

    runTask({
        foreach(immutable i; 5..10)
        {
            writeln(i);
            sleep(dur!"msecs"(1000));
            yield;
        }
    });

    runEventLoop();
}

It produces this:

0
5
1
6
2
7
3
8
4
9

I would expect:

0
5
1
2
3
4
6
7
8
9

Because after printing 5 (the first number), it yields and the other loop is the active fiber. The 5..10 foreach loop would continue execution after that fiber is done. But it seems like that 0..5 foreach loop seems to 'yield' at every sleep.

What am I missing here?