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)
| 248 | |
| 249 | |
| 250 | def 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 | |
| 270 | class _CloseSubscriber: |