Skip to content

Commit ec67428

Browse files
committed
examples: mqtt: pub sub: formatting
1 parent 63844f8 commit ec67428

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

examples/mqtt/pub_sub.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
import enapter
55

66

7+
async def main() -> None:
8+
config = enapter.mqtt.Config(host="127.0.0.1", port=1883)
9+
async with enapter.mqtt.Client(config=config) as client:
10+
async with asyncio.TaskGroup() as tg:
11+
tg.create_task(subscriber(client))
12+
tg.create_task(publisher(client))
13+
14+
715
async def subscriber(client: enapter.mqtt.Client) -> None:
816
async with client.subscribe("/+") as messages:
917
async for msg in messages:
@@ -19,13 +27,5 @@ async def publisher(client: enapter.mqtt.Client) -> None:
1927
await asyncio.sleep(1)
2028

2129

22-
async def main() -> None:
23-
config = enapter.mqtt.Config(host="127.0.0.1", port=1883)
24-
async with enapter.mqtt.Client(config=config) as client:
25-
async with asyncio.TaskGroup() as tg:
26-
tg.create_task(subscriber(client))
27-
tg.create_task(publisher(client))
28-
29-
3030
if __name__ == "__main__":
3131
asyncio.run(main())

0 commit comments

Comments
 (0)