MCPcopy
hub / github.com/bugy/script-server / read_until_closed

Function read_until_closed

src/react/observable.py:250–267  ·  view source on GitHub ↗

Reads and returns all available data in observable until it's closed :param observable: data to be read from :param timeout: (in sec, float) if timeout is set (non None and > 0) and wait takes more time, then TimeoutError is raised :return: all data (list), which will be read

(observable, timeout=None)

Source from the content-addressed store, hash-verified

248
249
250def read_until_closed(observable, timeout=None):
251 """
252 Reads and returns all available data in observable until it's closed
253 :param observable: data to be read from
254 :param timeout: (in sec, float) if timeout is set (non None and > 0) and wait takes more time,
255 then TimeoutError is raised
256 :return: all data (list), which will be read
257 """
258 observer = _StoringObserver()
259
260 observable.subscribe(observer)
261 observable.wait_close(timeout)
262
263 if (timeout is not None) and (not observable.closed):
264 observable.unsubscribe(observer)
265 raise TimeoutError('Observable was not closed within timeout period of ' + str(timeout) + ' sec')
266
267 return observer.data
268
269
270class _CloseSubscriber:

Calls 4

_StoringObserverClass · 0.85
subscribeMethod · 0.45
wait_closeMethod · 0.45
unsubscribeMethod · 0.45