XaverStiensmeier / ilarisdiscordbot

A discord bot for the ilaris ttrpg
GNU General Public License v3.0
0 stars 0 forks source link

Bug in save_yaml wrapper with async functions #80

Closed lukruh closed 1 month ago

lukruh commented 5 months ago

the data some times is written before async operations are finished. This can cause bugs for example: create group -> delete group -> channels are not always removed, as the channel id was returned from discord after writing finished. I'm not 100% sure if this error can be reproduced easily, but I made the wrapper aware of async functions. Not sure if this is the best way though:

def save_yaml(original_function):

    @wraps(original_function)
    def wrapper(*args, **kwargs):
        result = original_function(*args, **kwargs)
        write_yaml()
        return result

    @wraps(original_function)
    async def async_wrapper(*args, **kwargs):
        result = await original_function(*args, **kwargs)
        write_yaml()
        return result
    if asyncio.iscoroutinefunction(original_function):
        return async_wrapper
    else:
        return wrapper

will be added to #77