Skip to content

Commit

Permalink
Fix subscriber close issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Oct 14, 2024
1 parent 0d0043f commit 2f91045
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fastagency_studio/io/ionats.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ def start_chat() -> Optional[list[dict[str, Any]]]: # type: ignore [return]
task = asyncio.create_task(async_start_chat()) # type: ignore
background_tasks.add(task)

def callback(t: asyncio.Task[Any]) -> None:
async def callback(t: asyncio.Task[Any]) -> None:
try:
background_tasks.discard(t)
syncify(iostream.subscriber.close)()
await iostream.subscriber.close()
except Exception as e:
logger.error(f"Error in callback: {e}")
logger.error(traceback.format_exc())

task.add_done_callback(callback)
task.add_done_callback(lambda t: asyncio.create_task(callback(t)))

except Exception as e:
logger.error(f"Error in handling initiate chat: {e}")
Expand Down

0 comments on commit 2f91045

Please sign in to comment.