Skip to content

Commit

Permalink
Readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
neumond committed Jul 3, 2020
1 parent 762021a commit d43fb0d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,41 @@ async def program(api):
# and this snippet takes approximately 2 seconds to complete.
await asyncio.gather(api.os.sleep(2), api.os.sleep(2))
```

Opening a file:

```python
async def program(api):
async with api.fs.open('filename', 'r') as f:
async for line in f:
await api.print(line)
```

Capturing event:

```python
async def program(api):
async with api.os.captureEvent('timer') as timer_event_queue:
timer_id = await api.os.startTimer(2)
async for etid, *_ in timer_event_queue:
if etid == timer_id:
await api.print('Timer reached')
break
```

Using modems:

```python
async def program(api):
modem = await api.peripheral.wrap('back')
listen_channel = 5
async with modem.receive(listen_channel) as q:
async for msg in q:
await api.print(repr(msg))
if msg.content == 'stop':
break
else:
await modem.transmit(msg.reply_channel, listen_channel, msg.content)
```

More examples can be found in `testmod.py`.
3 changes: 3 additions & 0 deletions testmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ async def test_fs_api(api):
async with api.fs.open('tdir/binfile', 'rb') as f:
assert isinstance(await f.read(), int)

async with api.fs.open('tdir/binfile', 'r') as f:
assert [line async for line in f] == ['bbcccaaaaddd']

assert await api.fs.delete('tdir') is None
assert await api.fs.delete('tfile') is None
assert await api.fs.delete('doesnotexist') is None
Expand Down

0 comments on commit d43fb0d

Please sign in to comment.