1+ from asyncio import Future
12from collections .abc import Awaitable , Callable
23from datetime import timedelta
34from typing import Any , final , overload
@@ -42,8 +43,8 @@ class IteratorSubscription:
4243 """
4344
4445 def __aiter__ (self ) -> IteratorSubscription : ...
45- async def __anext__ (self ) -> Message : ...
46- async def next (self , timeout : float | timedelta | None = None ) -> Message :
46+ def __anext__ (self ) -> Future [ Message ] : ...
47+ def next (self , timeout : float | timedelta | None = None ) -> Future [ Message ] :
4748 """Receive the next message from the subscription.
4849
4950 :param timeout: maximum time to wait for a message in seconds
@@ -53,14 +54,14 @@ class IteratorSubscription:
5354 unsubscribed.
5455 """
5556
56- async def unsubscribe (self , limit : int | None = None ) -> None :
57+ def unsubscribe (self , limit : int | None = None ) -> Future [ None ] :
5758 """Unsubscribe from the subject.
5859
5960 :param limit: if set, automatically unsubscribe after receiving
6061 this many additional messages, defaults to None.
6162 """
6263
63- async def drain (self ) -> None :
64+ def drain (self ) -> Future [ None ] :
6465 """Drain the subscription.
6566
6667 Unsubscribes and flushes any remaining messages before closing.
@@ -74,14 +75,14 @@ class CallbackSubscription:
7475 Messages are automatically delivered to the callback in a background task.
7576 """
7677
77- async def unsubscribe (self , limit : int | None = None ) -> None :
78+ def unsubscribe (self , limit : int | None = None ) -> Future [ None ] :
7879 """Unsubscribe from the subject.
7980
8081 :param limit: if set, automatically unsubscribe after receiving
8182 this many additional messages, defaults to None.
8283 """
8384
84- async def drain (self ) -> None :
85+ def drain (self ) -> Future [ None ] :
8586 """Drain the subscription.
8687
8788 Unsubscribes and flushes any remaining messages before closing.
@@ -132,30 +133,30 @@ class Nats:
132133 in seconds or as a timedelta, defaults to 10 seconds.
133134 """
134135
135- async def startup (self ) -> None :
136+ def startup (self ) -> Future [ None ] :
136137 """Connect to the NATS server.
137138
138139 Establishes the connection using the parameters provided at
139140 construction time. Must be called before any publish, subscribe,
140141 or JetStream operations.
141142 """
142143
143- async def shutdown (self ) -> None :
144+ def shutdown (self ) -> Future [ None ] :
144145 """Close the NATS connection.
145146
146147 Drains all subscriptions and flushes pending data before
147148 disconnecting.
148149 """
149150
150- async def publish (
151+ def publish (
151152 self ,
152153 subject : str ,
153154 payload : bytes | str | bytearray | memoryview ,
154155 * ,
155156 headers : dict [str , Any ] | None = None ,
156157 reply : str | None = None ,
157158 err_on_disconnect : bool = False ,
158- ) -> None :
159+ ) -> Future [ None ] :
159160 """Publish a message to a subject.
160161
161162 :param subject: subject to publish the message to.
@@ -167,15 +168,15 @@ class Nats:
167168 is disconnected, defaults to False.
168169 """
169170
170- async def request (
171+ def request (
171172 self ,
172173 subject : str ,
173174 payload : bytes | str | bytearray | memoryview ,
174175 * ,
175176 headers : dict [str , Any ] | None = None ,
176177 inbox : str | None = None ,
177178 timeout : float | timedelta | None = None ,
178- ) -> Message :
179+ ) -> Future [ Message ] :
179180 """Send a request and discard the response.
180181
181182 :param subject: subject to send the request to.
@@ -188,31 +189,31 @@ class Nats:
188189 :return: response message.
189190 """
190191
191- async def drain (self ) -> None :
192+ def drain (self ) -> Future [ None ] :
192193 """Drain the connection.
193194
194195 Gracefully closes all subscriptions and flushes pending messages.
195196 """
196197
197- async def flush (self ) -> None :
198+ def flush (self ) -> Future [ None ] :
198199 """Flush the connection.
199200
200201 Waits until all pending messages have been sent to the server.
201202 """
202203
203204 @overload
204- async def subscribe (
205+ def subscribe (
205206 self ,
206207 subject : str ,
207208 callback : Callable [[Message ], Awaitable [None ]],
208- ) -> CallbackSubscription : ...
209+ ) -> Future [ CallbackSubscription ] : ...
209210 @overload
210- async def subscribe (
211+ def subscribe (
211212 self ,
212213 subject : str ,
213214 callback : None = None ,
214- ) -> IteratorSubscription : ...
215- async def jetstream (
215+ ) -> Future [ IteratorSubscription ] : ...
216+ def jetstream (
216217 self ,
217218 * ,
218219 domain : str | None = None ,
@@ -222,7 +223,7 @@ class Nats:
222223 concurrency_limit : int | None = None ,
223224 max_ack_inflight : int | None = None ,
224225 backpressure_on_inflight : bool | None = None ,
225- ) -> js .JetStream :
226+ ) -> Future [ js .JetStream ] :
226227 """Create a JetStream context.
227228
228229 :param domain: JetStream domain to use.
0 commit comments