Skip to content

Commit 0055e5a

Browse files
committed
Pattern matching fixes
1 parent 84ef2b9 commit 0055e5a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

aioreactive/combine.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ async def update(msg: Msg, model: Model[TSource]) -> Model[TSource]:
9595

9696
return model.replace(is_stopped=True)
9797

98-
# default case
99-
for key, dispose in model.subscriptions:
100-
await dispose.dispose_async()
98+
while m.default():
99+
for key, dispose in model.subscriptions:
100+
await dispose.dispose_async()
101+
101102
return initial_model.replace(is_stopped=True)
102103

103104
async def message_loop(model: Model[TSource]) -> None:
@@ -181,12 +182,14 @@ async def get_value(n: Notification[TSource]) -> Option[TSource]:
181182
await n.accept_observer(safe_obv)
182183
return Nothing
183184

184-
if isinstance(cn, SourceMsg):
185-
cn = cast(SourceMsg[TSource], cn)
186-
source_value = await get_value(cn.value)
187-
else:
188-
cn = cast(OtherMsg[TOther], cn)
189-
other_value = await get_value(cn.value)
185+
m = match(cn)
186+
for value in SourceMsg.case(m):
187+
source_value = await get_value(value)
188+
break
189+
190+
for value in OtherMsg.case(m):
191+
other_value = await get_value(value)
192+
break
190193

191194
def binder(s: TSource) -> Option[Tuple[TSource, TOther]]:
192195
def mapper(o: TOther) -> Tuple[TSource, TOther]:

aioreactive/timeshift.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def message_loop(current_index: int) -> Result[TSource, Exception]:
115115
elif index > current_index:
116116
current_index = index
117117

118-
for err in m.case(OnError):
118+
for err in OnError.case(m):
119119
await safe_obv.athrow(err)
120120

121121
while m.case(OnCompleted):

0 commit comments

Comments
 (0)