Skip to content

Commit

Permalink
Pattern matching fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrattli committed Nov 26, 2020
1 parent 84ef2b9 commit 0055e5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions aioreactive/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ async def update(msg: Msg, model: Model[TSource]) -> Model[TSource]:

return model.replace(is_stopped=True)

# default case
for key, dispose in model.subscriptions:
await dispose.dispose_async()
while m.default():
for key, dispose in model.subscriptions:
await dispose.dispose_async()

return initial_model.replace(is_stopped=True)

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

if isinstance(cn, SourceMsg):
cn = cast(SourceMsg[TSource], cn)
source_value = await get_value(cn.value)
else:
cn = cast(OtherMsg[TOther], cn)
other_value = await get_value(cn.value)
m = match(cn)
for value in SourceMsg.case(m):
source_value = await get_value(value)
break

for value in OtherMsg.case(m):
other_value = await get_value(value)
break

def binder(s: TSource) -> Option[Tuple[TSource, TOther]]:
def mapper(o: TOther) -> Tuple[TSource, TOther]:
Expand Down
2 changes: 1 addition & 1 deletion aioreactive/timeshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def message_loop(current_index: int) -> Result[TSource, Exception]:
elif index > current_index:
current_index = index

for err in m.case(OnError):
for err in OnError.case(m):
await safe_obv.athrow(err)

while m.case(OnCompleted):
Expand Down

0 comments on commit 0055e5a

Please sign in to comment.