nyxx-discord / nyxx

Wrapper around Discord API for Dart
Apache License 2.0
326 stars 49 forks source link

Ensure client.close() cleans up any pending async operations #655

Closed abitofevrything closed 6 months ago

abitofevrything commented 6 months ago

Description

A common problem with nyxx in previous versions has been that calling client.close() will return a future that completes, but the process will stay alive as the library was still doing some invisible async work in the background. In other words, client.close() didn't correctly dispose of all pending async operations.

This is still the case now, this time because of rate limits - the timers created through uses of Future.delayed kept the program alive until their callback was triggered, at which point nyxx realizes the client is closed and aborts the task. This PR fixes this issue by making uses of timers explicit and cancelling them when needed.

This PR also adds a test that ensures client.close(): 1) is quick, and does not hang 2) closes any streams/completes any futures returned by methods on the client 3) does not leave any hidden async operations running

Type of change

Checklist: