srecord noeq StupidFib_collab(ICollab collab, int n) { double timeout = 10.0; // if n <= parallelizationThreshold, we calculate serially gettable int parallelizationThreshold = 8; settable int delay = 0; // millisecond delay per add selfType parallelizationThreshold(int x) { parallelizationThreshold = max(3, x); this; } record noeq Step(int n, LongConsumer continuation) is Runnable { run { // fallback to serial case if (n < parallelizationThreshold) ret with continuation.accept(stupidFib(n)); LongPairCollector collector = new { void complete(long a, long b) { continuation.accept(add(a, b)); } }; collab.addWork(new Step(n-1, collector.setterForA())); collab.addWork(new Step(n-2, collector.setterForB())); } } long get() { new Var var; collab.addWork(new Step(n, result -> { var.set(result); collab.done(); })); collab.run(); ret waitForVarToBeNotNullWithTimeout(var, secondsToMS_int(timeout)); } long add(long a, long b) { if (delay > 0) sleep(delay); ret a+b; } }