@@ -64,14 +64,16 @@ def from_continuation_token(cls, continuation_token: str, **kwargs) -> Tuple[Any
64
64
raise TypeError ("Polling method '{}' doesn't support from_continuation_token" .format (cls .__name__ ))
65
65
66
66
67
- class NoPolling (PollingMethod ):
67
+ class NoPolling (PollingMethod , Generic [ PollingReturnType ] ):
68
68
"""An empty poller that returns the deserialized initial response."""
69
69
70
+ _deserialization_callback : Callable [[Any ], PollingReturnType ]
71
+ """Deserialization callback passed during initialization"""
72
+
70
73
def __init__ (self ):
71
74
self ._initial_response = None
72
- self ._deserialization_callback = None
73
75
74
- def initialize (self , _ : Any , initial_response : Any , deserialization_callback : Callable ) -> None :
76
+ def initialize (self , _ : Any , initial_response : Any , deserialization_callback : Callable [[ Any ], PollingReturnType ] ) -> None :
75
77
self ._initial_response = initial_response
76
78
self ._deserialization_callback = deserialization_callback
77
79
@@ -92,7 +94,7 @@ def finished(self) -> bool:
92
94
"""
93
95
return True
94
96
95
- def resource (self ) -> Any :
97
+ def resource (self ) -> PollingReturnType :
96
98
return self ._deserialization_callback (self ._initial_response )
97
99
98
100
def get_continuation_token (self ) -> str :
@@ -130,7 +132,7 @@ def __init__(
130
132
self ,
131
133
client : Any ,
132
134
initial_response : Any ,
133
- deserialization_callback : Callable ,
135
+ deserialization_callback : Callable [[ Any ], PollingReturnType ] ,
134
136
polling_method : PollingMethod [PollingReturnType ],
135
137
) -> None :
136
138
self ._callbacks : List [Callable ] = []
@@ -147,10 +149,11 @@ def __init__(
147
149
148
150
# Prepare thread execution
149
151
self ._thread = None
150
- self ._done = None
152
+ self ._done = threading . Event ()
151
153
self ._exception = None
152
- if not self ._polling_method .finished ():
153
- self ._done = threading .Event ()
154
+ if self ._polling_method .finished ():
155
+ self ._done .set ()
156
+ else :
154
157
self ._thread = threading .Thread (
155
158
target = with_current_context (self ._start ),
156
159
name = "LROPoller({})" .format (uuid .uuid4 ()),
@@ -266,7 +269,7 @@ def add_done_callback(self, func: Callable) -> None:
266
269
argument, a completed LongRunningOperation.
267
270
"""
268
271
# Still use "_done" and not "done", since CBs are executed inside the thread.
269
- if self ._done is None or self . _done .is_set ():
272
+ if self ._done .is_set ():
270
273
func (self ._polling_method )
271
274
# Let's add them still, for consistency (if you wish to access to it for some reasons)
272
275
self ._callbacks .append (func )
0 commit comments