Asynchronous Calls

Is there a way to setup asychronous calls in IronRuby. I’ve used things
like WebClient.download_string_async, but I’m wondering if I can setup
an async using just IronRuby.

For example:
@data.get_settings do |settings|

do stuff after async call


Where get_settings is an async method and it executes the block after it
is completed.

Thanks for any help,

What do you mean by “set up asynchronous calls”?

If your get_settings method is a C# method using the IAsyncResult
pattern, then you should be able to invoke it from IronRuby.

From memory you can pass a ruby Proc in place of the AsyncCallback and it should all work:


callback = lambda{ |asyncresult| puts data.end_get_settings(asyncresult)
data.begin_get_settings(“abc”, callback, nil)

If you want to write your own asynchronous method not involving C# at
all, then you can do that too. If that’s the case, then all you really
need to do is remember to call the block when you’re done.


def get_settings(&block)
settings = 123

In a real function you’d probably run the body of get_settings in
another thread, but I won’t go into how to do threading, as there may be
other better ways depending on your situation.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs