mschilli / net-google-drive-simple

Net::Google::Drive::Simple CPAN Module
Other
11 stars 22 forks source link

Built-in support for event loops #62

Open xsawyerx opened 2 years ago

xsawyerx commented 2 years ago

Since this module primarily does I/O, it would be good to support an event loop.

I've made the resumable upload method upload_file_content_iterator() for this purpose, but it doesn't help that everything else is done with synchronous requests, including the preliminary request that is required for this method (create_resumable_upload() or create_resumable_upload_for()).

I can think of several ways to try and support event loops:

  1. We can switch to an event loop. My money is on IO::Async since it works with other loops and its author is active and friendly.
  2. Same as No. 1 but make it optional, like a setting or a detection.
  3. We can come up with a simple way to subclass the http_loop() method so people can create their own variations.
  4. We can have a parameter for the http_loop() that makes it easy to hook up another event loop (this is tricky)
  5. We can make the request a hook instead, so people can provide a callback for handling requests (this is also tricky)
  6. We can add an optional callback for every operation and set the default to what we would do with it
  7. Switch everything to Promises or Futures and allow the user to trigger the call

I haven't yet looked enough into it to decide which approach is best but I'm inclined to go with No. 7 since it provides the cleanest interface for handling sync and async by making everything a Future that is either satisfied immediately (sync) or later (async) by whatever event loop you are using. Future.pm has clean interfaces for many event loops and you can always add your own easily.