Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fibonacci Await
import asyncio
async def fibonacci(n, marker):
print(f'Marker: {marker}')
if n < 2:
return 1
return await fibonacci(n-1, marker) + await fibonacci(n-2, marker)
async def main():
await asyncio.gather(
fibonacci(5, 'A'),
fibonacci(6, 'B'),
)
asyncio.run(main())
@caulagi
Copy link
Author

caulagi commented Dec 10, 2018

$ python fib-4.py 
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: A
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B
Marker: B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment