Skip to content

Commit 3db5d87

Browse files
committed
MOD: Add task for subscribe
1 parent 779c0ef commit 3db5d87

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

databento/live/session.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,15 @@ def subscribe(
366366
loop=self._loop,
367367
)
368368

369-
self._protocol.subscribe(
369+
asyncio.run_coroutine_threadsafe(
370+
self._subscribe_task(
370371
schema=schema,
371372
symbols=symbols,
372373
stype_in=stype_in,
373374
start=start,
374-
)
375+
),
376+
loop=self._loop,
377+
).result()
375378

376379
def resume_reading(self) -> None:
377380
"""
@@ -496,3 +499,21 @@ async def _connect_task(
496499
)
497500

498501
return transport, protocol
502+
503+
async def _subscribe_task(
504+
self,
505+
schema: Schema | str,
506+
symbols: Iterable[str] | Iterable[Number] | str | Number = ALL_SYMBOLS,
507+
stype_in: SType | str = SType.RAW_SYMBOL,
508+
start: str | int | None = None,
509+
) -> None:
510+
with self._lock:
511+
if self._protocol is None:
512+
return
513+
514+
self._protocol.subscribe(
515+
schema=schema,
516+
symbols=symbols,
517+
stype_in=stype_in,
518+
start=start,
519+
)

0 commit comments

Comments
 (0)