Skip to content

Instantly share code, notes, and snippets.

@caulagi
Created December 10, 2018 12:23
Show Gist options
  • Save caulagi/3edea8cf734495f2592528a48f99e1d2 to your computer and use it in GitHub Desktop.
Save caulagi/3edea8cf734495f2592528a48f99e1d2 to your computer and use it in GitHub Desktop.
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