Skip to content

Commit 5fc8335

Browse files
committed
Fix Middleware Chain to Allow Awaiting Final Logic Result
1 parent bd5662a commit 5fc8335

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

libraries/botbuilder-core/botbuilder/core/turn_context.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,15 @@ async def _emit(self, plugins, arg, logic):
288288

289289
async def emit_next(i: int):
290290
context = self
291-
try:
292-
if i < len(handlers):
293-
294-
async def next_handler():
295-
await emit_next(i + 1)
296-
297-
await handlers[i](context, arg, next_handler)
298-
299-
except Exception as error:
300-
raise error
301-
302-
await emit_next(0)
303-
# logic does not use parentheses because it's a coroutine
304-
return await logic
291+
if i < len(handlers):
292+
try:
293+
return await handlers[i](context, arg, lambda: emit_next(i + 1))
294+
except Exception as error:
295+
raise error
296+
else:
297+
return await logic
298+
299+
return await emit_next(0)
305300

306301
async def send_trace_activity(
307302
self, name: str, value: object = None, value_type: str = None, label: str = None

libraries/botbuilder-core/tests/test_turn_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ async def update_handler(context, activity, next_handler_coroutine):
241241
assert context is not None
242242
assert activity.id == activity_id
243243
assert activity.conversation.id == ACTIVITY.conversation.id
244-
await next_handler_coroutine()
244+
return await next_handler_coroutine()
245245

246246
context.on_update_activity(update_handler)
247247
new_activity = MessageFactory.text("test text")

0 commit comments

Comments
 (0)