Floating-Dartists / matomo-tracker

A fully cross-platform wrap of the Matomo tracking client for Flutter, using the Matomo API.
https://pub.dev/packages/matomo_tracker
MIT License
26 stars 28 forks source link

Ability to drop the Dispatch Queue #89

Closed EPNW-Eric closed 1 year ago

EPNW-Eric commented 1 year ago

I added dropActions to manually clear the dispatch queue.

I also renamed dispatchEvents to dispatchActions, because technically, those are actions and not only events (events are a subtype of actions) and I wanted to lower the confusion potential by using the correct Matomo nomenclature.

Also, can someone explain why the return type of (now) dispatchActions and _dequeue is FutureOr and not simply Future?

EPNW-Eric commented 1 year ago

Thanks for the clarification about FutureOr 😊.

EPNW-Eric commented 1 year ago

Thanks for the contribution! 👍 dispatchActions is of type FutureOr because of the signature of the _dequeue method which itself is of this type because we are only returning an instance of Future (with return _lock.synchronized()) if the process is not locked. For _dequeue to be a Future we'd have to make the method async which was deemed unneeded as we don't need to use the await keyword.

I just found https://dart.dev/effective-dart/design#avoid-using-futureort-as-a-return-type, and I think it might be a good idea to follow this, but I don't know how to apply that here in a way that there are now unintended side effects with locking...

TesteurManiak commented 1 year ago

@EPNW-Eric I agree that following Dart guidelines should be the way to go, I'll do the appropriate refactor to change that