On Wednesday, 18 October 2017 at 11:01:56 UTC, Per Nordlöw wrote:
On Wednesday, 18 October 2017 at 09:01:30 UTC, Per Nordlöw wrote:
Creates an actor (goroutine, whatever), which spawns 10 new actors, each of them spawns 10 more actors, etc. until one million actors are created on the final level. Then, each of them returns back its ordinal number (from 0 to 999999), which are summed on the previous level and sent back upstream, until reaching the root actor. (The answer should be 499999500000).

See also: https://github.com/atemerev/skynet

I Fibers aren't supposed to take any parameters how are we supposed to pass values to it during creation?

Someone should really implement sth. along this line.

```d
  size_t cumsum(Fiber!int fib, size_t val)
  {
    size_t sum = val;
    foreach (i; 0 .. 10)
    {
        val = fib.yield(sum); // yield sum, get next val
        sum += val;
    }
    return sum;
  }
  auto fib = fiber!func;
  while (fib.state != Fiber.State.hold)
      writeln(fib.call(random()));
```

There is https://dlang.org/library/std/concurrency/generator.this.html, but it's not too well designed, relying on an runtime type cast in Fiber.yield which will fail if the yielded value isn't exactly of the same specified as template parameter.
https://github.com/dlang/phobos/pull/1910#r16965194

Reply via email to