ruby-concurrency / concurrent-ruby

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.
https://ruby-concurrency.github.io/concurrent-ruby/
Other
5.66k stars 417 forks source link

Add keyword arguments to async #1040

Open reeganviljoen opened 4 months ago

reeganviljoen commented 4 months ago

Feature request

Add support for keyword arguments when using async

From the docs

class Echo
  include [Concurrent](https://ruby-concurrency.github.io/concurrent-ruby/1.2.3/Concurrent.html)::Async

  def echo(msg)
    print "#{msg}\n"
  end
end

horn = Echo.new
horn.echo('zero')      # synchronous, not thread-safe
                       # returns the actual return value of the method

horn.async.echo('one') # asynchronous, non-blocking, thread-safe
                       # returns an IVar in the :pending state

horn.await.echo('two') # synchronous, blocking, thread-safe

but if i modify it to use named arguments like so it doesn't work

class Echo
  include [Concurrent](https://ruby-concurrency.github.io/concurrent-ruby/1.2.3/Concurrent.html)::Async

  def echo(msg: )
    print "#{msg}\n"
  end
end

horn = Echo.new
horn.echo(msg: zero')      # synchronous, not thread-safe
                       # returns the actual return value of the method

horn.async.echo(msg: 'one') # asynchronous, non-blocking, thread-safe
                       # returns an IVar in the :pending state

horn.await.echo(msg: 'two') # synchronous, blocking, thread-safe

#when I try to get the value 
horn.await.echo(msg: 'two').value #nil
horn.await.echo(msg: 'two').reason #<ArgumentError: wrong number of arguments (given 1, expected 0)>

I appreciate any future feedback from the maintainers on this 🙏

System information

* Operating system:                mac
* Ruby implementation:             Ruby
* `concurrent-ruby` version:       1,2,3
* `concurrent-ruby-ext` installed: no
* `concurrent-ruby-edge` used:     no
turnon commented 4 months ago

There is nothing wrong to get nil from value. Because print just write to STDOUT and return nil

And I can not reproduce ArgumentError from reason. Would you try that again ?