Skip to content

Commit 31a2478

Browse files
committed
remove fire-and-forget methods | remove _async in methods name
1 parent 16070e0 commit 31a2478

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Deployed online documentation: https://flet-dev.github.io/flet-flashlight/
1313
- `Flashlight` control new properties: `on`, `on_error`
14-
- `Flashlight` control new methods: `is_available_async`
14+
- `Flashlight` control new methods: `is_available`
1515
- New exception classes:
1616
- `FlashlightException`
1717
- `FlashlightEnableExistentUserException`
@@ -32,4 +32,4 @@ Initial release.
3232

3333

3434
[0.2.0]: https://github.com/flet-dev/flet-flashlight/compare/0.1.0...0.2.0
35-
[0.1.0]: https://github.com/flet-dev/flet-flashlight/releases/tag/0.1.0
35+
[0.1.0]: https://github.com/flet-dev/flet-flashlight/releases/tag/0.1.0

src/flet_flashlight/flashlight.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
from typing import Optional
32

43
import flet as ft
@@ -39,11 +38,11 @@ class Flashlight(ft.Service):
3938
contains information on the error.
4039
"""
4140

42-
async def turn_on_async(self):
41+
async def turn_on(self):
4342
"""
4443
Turns the flashlight on.
4544
"""
46-
r = await self._invoke_method_async("on")
45+
r = await self._invoke_method("on")
4746
if r is True:
4847
self.on = True
4948
else: # error occured
@@ -56,17 +55,11 @@ async def turn_on_async(self):
5655
else:
5756
raise FlashlightEnableException(error_msg)
5857

59-
def turn_on(self):
60-
"""
61-
Turns the flashlight on.
62-
"""
63-
asyncio.create_task(self.turn_on_async())
64-
65-
async def turn_off_async(self):
58+
async def turn_off(self):
6659
"""
6760
Turns the flashlight off.
6861
"""
69-
r = await self._invoke_method_async("off")
62+
r = await self._invoke_method("off")
7063
if r is True:
7164
self.on = False
7265
else: # error occured
@@ -79,31 +72,19 @@ async def turn_off_async(self):
7972
else:
8073
raise FlashlightDisableException(error_msg)
8174

82-
def turn_off(self):
83-
"""
84-
Turns the flashlight off.
85-
"""
86-
asyncio.create_task(self.turn_off_async())
87-
88-
async def toggle_async(self):
75+
async def toggle(self):
8976
"""
9077
Toggles the flashlight on and off.
9178
"""
9279
if self.on:
93-
await self.turn_off_async()
94-
await self.turn_on_async()
95-
96-
def toggle(self):
97-
"""
98-
Toggles the flashlight on and off.
99-
"""
100-
asyncio.create_task(self.toggle_async())
80+
await self.turn_off()
81+
await self.turn_on()
10182

102-
async def is_available_async(self):
83+
async def is_available(self):
10384
"""
10485
Checks if the flashlight is available on the device.
10586
"""
106-
r = await self._invoke_method_async("is_available")
87+
r = await self._invoke_method("is_available")
10788
if r is bool:
10889
return r
10990
else: # error occured

0 commit comments

Comments
 (0)