I am using a third party .Net library in Python 3.6 via Python for .Net which uses EventHandlers to provide asynchronous data to my application, similar to the toy example below:
import clr
from System import Timers
def tock(__, args):
print(args.SignalTime)
timer = Timers.Timer()
timer.Interval = 1000
timer.Elapsed += tock
timer.Enabled = True
while True:
pass
I would like to get this data into an asynchronous generator, something like:
import clr
from System import Timers
async def tock(__, args):
yield args.SignalTime
async def main():
result = await tock
print(result)
timer = Timers.Timer()
timer.Interval = 1000
timer.Elapsed += tock
timer.Enabled = True
while true:
result = await timer
print result
Obiviously just throwing asyc and yield on the event handler function and awaiting the timer won't do it, but is there a straightforward means of accomplishing this?