Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the collection of task values and errors #5

Merged
merged 3 commits into from
Mar 19, 2024
Merged

Commits on Mar 19, 2024

  1. Add a very crude comparative benchmark.

    Roughly compare the performance of accumulating values with a separate
    goroutine via a channel, vs. accumulating them directly under a lock.
    creachadair committed Mar 19, 2024
    Configuration menu
    Copy the full SHA
    7b70cfe View commit details
    Browse the repository at this point in the history
  2. Simplify the implementation of the Collector.

    Instead of maintaining a separate goroutine to synchronize delivery of values,
    rework the collector to use a plain sync.Mutex.
    
    This:
    
    - Greatly simplifies the code (with one exception, noted below).
    
    - Eliminates the need for a separate goroutine to service values. Each task now
      handles its own service, mediated by the collector. That, in turn:
    
    - Eliminates the need to Wait for the Collector: Once all the goroutines
      running tasks in the collector have exited, the state is fully settled.
      The Wait method is now a no-op, and is marked as deprecated.
    
    In addition, add a new Report method, replacing Stream. Instead of a channel,
    tasks using this method accepts a report function that sends values to the
    collector.  The report function ensures control does not return to the task
    until the reported value has been serviced, which allows tasks to ensure they
    do not exit until all their values have been addressed.
    
    The Stream method still works, but is deprecated. To preserve its interface,
    each Stream call now spins up a new goroutine to service the values from its
    task. This is wasteful, but easily replaced by switching to Report.
    
    Co-Authored-By: David Anderson <dave@natulte.net>
    creachadair and danderson committed Mar 19, 2024
    Configuration menu
    Copy the full SHA
    e4cc5a5 View commit details
    Browse the repository at this point in the history
  3. Simplify the implementation of the Group.

    Remove the separate goroutine collecting errors, and deliver them directly to
    the error filter and the output field. Moreover simplify the setup and teardown
    so that there is not so much coordinated state. Although performance was not a
    primary consideration, benchmarking suggests this is actually faster than the
    previous implementation, and uses less memory.
    
    Also expand and clarify the documentation of the Wait method.
    
    Co-Authored-By: David Anderson <dave@natulte.net>
    creachadair and danderson committed Mar 19, 2024
    Configuration menu
    Copy the full SHA
    d5e9b4f View commit details
    Browse the repository at this point in the history