File par/1-spinner/spinner.d from the latest check-in


import std.stdio;
import std.concurrency;
import core.thread;

void main() {
    spawnLinked(&spinner, 100.msecs);
    enum n = 45;
    auto fibN = fib(n); // slow
    writefln!"\rFibonacci(%d) = %d"(n, fibN);
}

void spinner(const Duration delay) {
    while (true) {
        bool done;
        foreach (r; `-\|/`) {
            writef!"\r%c"(r);
            stdout.flush;
            receiveTimeout(delay, (OwnerTerminated msg) { done = true; });
            if (done)
                return;
        }
    }
}

int fib(int x) pure {
    return x < 2 ? x : fib(x - 1) + fib(x - 2);
}