Skip to content

Commit 62d21c4

Browse files
authored
Fix async examples in README (#2553)
The Future example compared the result to 2 instead of IO(2), and the FutureResult example passed the function instead of calling it.
1 parent 808c168 commit 62d21c4

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,11 @@ However, `Future` still requires to be executed inside a proper eventloop:
540540

541541
```python
542542
import anyio # or asyncio, or any other lib
543+
from returns.io import IO
543544

544545
# We can then pass our `Future` to any library: asyncio, trio, curio.
545546
# And use any event loop: regular, uvloop, even a custom one, etc
546-
assert anyio.run(second().awaitable) == 2
547+
assert anyio.run(second().awaitable) == IO(2)
547548
```
548549

549550
As you can see `Future` allows you
@@ -579,8 +580,9 @@ async def raising():
579580
raise ValueError('Not so fast!')
580581

581582

582-
ioresult = anyio.run(raising.awaitable) # all `Future`s return IO containers
583-
assert ioresult == IOFailure(ValueError('Not so fast!')) # True
583+
ioresult = anyio.run(raising().awaitable) # all `Future`s return IO containers
584+
assert isinstance(ioresult, IOFailure)
585+
assert str(ioresult) == '<IOResult: <Failure: Not so fast!>>'
584586
```
585587

586588
Using `FutureResult` will keep your code safe from exceptions.

0 commit comments

Comments
 (0)