File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ async def wrapper(*args, **kwargs):
93
93
with trace:
94
94
while True:
95
95
try:
96
- g.asend(value).send(None )
96
+ yielded = await g.asend(value)
97
97
except StopAsyncIteration as e:
98
98
# The underlying async generator has finished, return propagates a new StopAsyncIteration
99
99
return
@@ -107,7 +107,7 @@ async def wrapper(*args, **kwargs):
107
107
# An exception was thrown with .athrow(), propagate to the original async generator.
108
108
# Return value logic must be identical to .asend()
109
109
try:
110
- g.athrow(type(e), e).send(None )
110
+ value = yield await g.athrow(type(e), e)
111
111
except StopAsyncIteration as e:
112
112
# The underlying async generator has finished, return propagates a new StopAsyncIteration
113
113
return
Original file line number Diff line number Diff line change @@ -260,6 +260,37 @@ async def _test():
260
260
assert full_metrics [key ].total_exclusive_call_time < 0.2
261
261
262
262
263
+ @validate_transaction_metrics (
264
+ "test_asend_receives_a_value" ,
265
+ background_task = True ,
266
+ scoped_metrics = [("Function/agen" , 1 )],
267
+ rollup_metrics = [("Function/agen" , 1 )],
268
+ )
269
+ def test_asend_receives_a_value (event_loop ):
270
+ _received = []
271
+ @function_trace (name = "agen" )
272
+ async def agen ():
273
+ value = yield
274
+ _received .append (value )
275
+ yield value
276
+
277
+ @background_task (name = "test_asend_receives_a_value" )
278
+ async def _test ():
279
+ gen = agen ()
280
+
281
+ # kickstart the coroutine
282
+ await anext (gen )
283
+
284
+ assert await gen .asend ("foobar" ) == "foobar"
285
+ assert _received and _received [0 ] == "foobar"
286
+
287
+ # finish consumption of the coroutine if necessary
288
+ async for _ in gen :
289
+ pass
290
+
291
+ event_loop .run_until_complete (_test ())
292
+
293
+
263
294
@validate_transaction_metrics (
264
295
"test_athrow_yields_a_value" ,
265
296
background_task = True ,
You can’t perform that action at this time.
0 commit comments