[ create a new paste ] login | about

Link: http://codepad.org/I5BKFK2W    [ raw code | fork ]

aaronla - Plain Text, pasted on Oct 14:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// async fibonacci
function async_fib(x) { return spawn(function*() {
  throw new Task.Result(
    x < 2 ? x 
          : yield async_fib(x-1) + yield async_fib(x-2));
});}

// with fibers / awaits:
async int async_fib(int x) {
  return x < 2 ? x 
               : await async_fib(x-1) + await async_fib(x-2);
}
    


Create a new paste based on this one


Comments: