File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -52,3 +52,41 @@ async def program(api):
5252 # and this snippet takes approximately 2 seconds to complete.
5353 await asyncio.gather(api.os.sleep(2 ), api.os.sleep(2 ))
5454```
55+
56+ Opening a file:
57+
58+ ``` python
59+ async def program (api ):
60+ async with api.fs.open(' filename' , ' r' ) as f:
61+ async for line in f:
62+ await api.print(line)
63+ ```
64+
65+ Capturing event:
66+
67+ ``` python
68+ async def program (api ):
69+ async with api.os.captureEvent(' timer' ) as timer_event_queue:
70+ timer_id = await api.os.startTimer(2 )
71+ async for etid, * _ in timer_event_queue:
72+ if etid == timer_id:
73+ await api.print(' Timer reached' )
74+ break
75+ ```
76+
77+ Using modems:
78+
79+ ``` python
80+ async def program (api ):
81+ modem = await api.peripheral.wrap(' back' )
82+ listen_channel = 5
83+ async with modem.receive(listen_channel) as q:
84+ async for msg in q:
85+ await api.print(repr (msg))
86+ if msg.content == ' stop' :
87+ break
88+ else :
89+ await modem.transmit(msg.reply_channel, listen_channel, msg.content)
90+ ```
91+
92+ More examples can be found in ` testmod.py ` .
Original file line number Diff line number Diff line change @@ -502,6 +502,9 @@ async def test_fs_api(api):
502502 async with api .fs .open ('tdir/binfile' , 'rb' ) as f :
503503 assert isinstance (await f .read (), int )
504504
505+ async with api .fs .open ('tdir/binfile' , 'r' ) as f :
506+ assert [line async for line in f ] == ['bbcccaaaaddd' ]
507+
505508 assert await api .fs .delete ('tdir' ) is None
506509 assert await api .fs .delete ('tfile' ) is None
507510 assert await api .fs .delete ('doesnotexist' ) is None
You can’t perform that action at this time.
0 commit comments