🪟 Windows TippsBitLocker stuck on Decrypting or Encrypting in Windows 11(17.09.2026 um 00:29 Uhr)
🕵️ SicherheitslückenCVE-2026-69110 | Microck opencode-studio up to 2.4.3 missing authentication(17.09.2026 um 03:21 Uhr)
🪟 Windows TippsBitLocker stuck on Decrypting or Encrypting in Windows 11(17.09.2026 um 00:29 Uhr)
🕵️ SicherheitslückenCVE-2026-69110 | Microck opencode-studio up to 2.4.3 missing authentication(17.09.2026 um 03:21 Uhr)
🔧 Programmierung 🕛 vor 1 Jahr 5 Min Lesezeit
0

Async Pipeline Haystack Streaming over FastAPI Endpoint

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

If you are from Haystack, this blog is not for you!









Need for this blog



Love the haystack team and I hope they roll out a RC soon on for the or .



If not, follow the code snippet and I'll try to explain why we have it implemented this way.




CODE
   async def run_pipeline(self, pipeline: AsyncPipeline, input_data: Dict[str, Any]) -> AsyncGenerator[str, None]:
request_collector = ChunkCollector() # code snippet is below
loop = asyncio.get_running_loop()

# Create sync wrapper for async callback
async def async_callback(chunk):
await collect_chunk(request_collector.queue, chunk) # code snippet is below

def sync_callback(chunk):
# Use run_coroutine_threadsafe instead of create_task
future = asyncio.run_coroutine_threadsafe(async_callback(chunk), loop)
try:
# Wait for the coroutine to complete
future.result()
except Exception as e:
print(f"Error in sync_callback: {str(e)}")

# Set callbacks using sync wrapper
input_data["generator"]["streaming_callback"] = sync_callback

async def pipeline_runner():
try:
async for _ in pipeline.run(input_data):
pass
finally:
await request_collector.queue.put(None)

# Create task for pipeline
pipeline_task = asyncio.create_task(pipeline_runner())

try:
# Start yielding chunks
async for chunk in request_collector.generator():
yield chunk
finally:
# Ensure pipeline task is cleaned up
if not pipeline_task.done():
pipeline_task.cancel()
try:
await pipeline_task
except asyncio.CancelledError:
pass






Some Q/A's for you



* Why dont we do a direct async callback without wrapping?




CODE
    async def callback(chunk):
await collect_chunk(request_collector.queue, chunk)

input_data["generator"]["streaming_callback"] = callback






The generator is calling the callback synchronously, but we're passing an async function. So, we need a sync wrapper around our async callback, instead of trying to await an async generator.



* Why dont we just create a task?




CODE
    def sync_callback(chunk):
asyncio.create_task(async_callback(chunk))






The callback is being called from a different thread where there's no event loop. So, we need a thread-safe way to schedule the callback.






Chunking in SSE Format



We need to define the request_collector which handles the queue, stores the chunks and also yeilds the chunks from the queue(in SSE format).




CODE
from typing import AsyncGenerator

import uuid
import json

from asyncio import Queue

from haystack.dataclasses import StreamingChunk

class ChunkCollector:
"""Collects and queues streaming chunks."""
def __init__(self):
self.queue = Queue()

async def generator(self) -> AsyncGenerator[str, None]:
"""Yields chunks from the queue."""
# Send initial metadata event
yield 'event: metadata\n' + f'data: {{"run_id": "{uuid.uuid4()}"}}\n\n'

while True:
chunk = await self.queue.get()
if chunk is None:
# Send end event
yield 'event: end\n\n'
break
# Send data event
yield f'event: data\ndata: {json.dumps(chunk)}\n\n'

async def collect_chunk(queue: Queue, chunk: StreamingChunk):
"""
Collect chunks and store them in the queue.

:param queue: Queue to store the chunks
:param chunk: StreamingChunk to be collected
"""
if chunk and chunk.content:
await queue.put(chunk.content)









Frontend



You can directcly use EventSource or fetch. For this tutorial, let's use here as sockets will be just 👌🏽



vblagoje saying what if there was generator/iterator output socket on all ChatGenerators






If you found this blog helpful, just send a good vibe my way—whether it’s my (research taking off || side project getting some honey || landing some gigs) ✌🏽!

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
2 Quellen
CVE-2026-92597 | Nodemailer up to 9.0.x Addressparser lib/addressparser input validation (EUVD-2026-81297)
1 Quelle
BitLocker stuck on Decrypting or Encrypting in Windows 11
1 Quelle
CVE-2026-92599 | hapijs joi up to 17.13.6/18.0.0-18.2.5 isoDate Joi.string.isoDate redos (EUVD-2026-81299)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Async Pipeline Haystack Streaming over FastAPI Endpoint

Thematisch verwandte Begriffe: Async, Pipeline, Haystack, Streaming · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...