forked from goodboy/tractor
1
0
Fork 0

Add `aclosing()` around asyn gen loop

actor_state_via_messages
Tyler Goodlet 2021-01-24 13:14:17 -05:00
parent 5db737d368
commit 2ed071c903
2 changed files with 5 additions and 3 deletions

View File

@ -16,6 +16,7 @@ import time
import tractor import tractor
import trio import trio
from async_generator import aclosing
PRIMES = [ PRIMES = [
@ -103,8 +104,9 @@ async def main():
async with worker_pool() as actor_map: async with worker_pool() as actor_map:
start = time.time() start = time.time()
# for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)):
async for number, prime in actor_map(is_prime, PRIMES): async with aclosing(actor_map(is_prime, PRIMES)) as results:
async for number, prime in results:
print(f'{number} is prime: {prime}') print(f'{number} is prime: {prime}')