Skip to content

Commit fa152f5

Browse files
committed
Better represent the return of streaming as a generator
1 parent 8cd1ce6 commit fa152f5

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

ldclient/impl/datasourcev2/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from abc import abstractmethod
1414
from dataclasses import dataclass
15-
from typing import Iterable, Mapping, Optional, Protocol, Tuple
15+
from typing import Generator, Iterable, Mapping, Optional, Protocol, Tuple
1616

1717
from ldclient.impl.datasystem.protocolv2 import ChangeSet, Selector
1818
from ldclient.impl.util import _Result
@@ -65,7 +65,7 @@ class Synchronizer(Protocol): # pylint: disable=too-few-public-methods
6565
"""
6666

6767
@abstractmethod
68-
def sync(self) -> Iterable[Update]:
68+
def sync(self) -> Generator[Update, None, None]:
6969
"""
7070
sync should begin the synchronization process for the data source, yielding
7171
Update objects until the connection is closed or an unrecoverable error

ldclient/impl/datasourcev2/streaming.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
import json
77
from abc import abstractmethod
88
from time import time
9-
from typing import Callable, Iterable, Optional, Protocol, Tuple
9+
from typing import Callable, Generator, Iterable, Optional, Protocol, Tuple
1010
from urllib import parse
1111

1212
from ld_eventsource import SSEClient as SSEClientImpl
1313
from ld_eventsource.actions import Action, Event, Fault
14-
from ld_eventsource.config import (
15-
ConnectStrategy,
16-
ErrorStrategy,
17-
RetryDelayStrategy
18-
)
14+
from ld_eventsource.config import ConnectStrategy, ErrorStrategy, RetryDelayStrategy
1915
from ld_eventsource.errors import HTTPStatusError
2016

2117
from ldclient.config import Config
@@ -29,18 +25,14 @@
2925
IntentCode,
3026
PutObject,
3127
Selector,
32-
ServerIntent
28+
ServerIntent,
3329
)
3430
from ldclient.impl.http import HTTPFactory, _http_factory
35-
from ldclient.impl.util import (
36-
http_error_message,
37-
is_http_error_recoverable,
38-
log
39-
)
31+
from ldclient.impl.util import http_error_message, is_http_error_recoverable, log
4032
from ldclient.interfaces import (
4133
DataSourceErrorInfo,
4234
DataSourceErrorKind,
43-
DataSourceState
35+
DataSourceState,
4436
)
4537

4638
# allows for up to 5 minutes to elapse without any data sent across the stream.
@@ -129,7 +121,7 @@ def __init__(
129121
self._config = config
130122
self._sse: Optional[SSEClient] = None
131123

132-
def sync(self) -> Iterable[Update]:
124+
def sync(self) -> Generator[Update, None, None]:
133125
"""
134126
sync should begin the synchronization process for the data source, yielding
135127
Update objects until the connection is closed or an unrecoverable error

0 commit comments

Comments
 (0)