# Asynchronous Calls

**URL:** <https://www.ruby-forum.com/t/asynchronous-calls/182051>\
**Category:** IronRuby\
**Created:** [January 22, 2010, 12:04am UTC](https://www.ruby-forum.com/t/asynchronous-calls/182051 "2010-01-22T00:04:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Randall\_Sutton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/85e7bf/32.png) [@Randall\_Sutton](https://www.ruby-forum.com/u/Randall_Sutton)\
**Post date:** [January 22, 2010, 12:04am UTC](https://www.ruby-forum.com/t/asynchronous-calls/182051/1 "2010-01-22T00:04:57Z")

</div>

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

end

Where get\_settings is an async method and it executes the block after it  
is completed.

Thanks for any help,  
Randall

---

<div class="post-metadata">

**Author:** ![Randall\_Sutton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/85e7bf/32.png) [@Randall\_Sutton](https://www.ruby-forum.com/u/Randall_Sutton)\
**Post date:** [January 22, 2010, 6:27am UTC](https://www.ruby-forum.com/t/asynchronous-calls/182051/2 "2010-01-22T06:27:44Z")

</div>

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:

Example:

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.

Example

def get\_settings(&block)  
do\_long\_thing  
settings = 123  
block.call(settings)  
end

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.

Cheers
