From: Jacob Repp Date: 2006-02-24T18:05:55+09:00 Subject: Re: Question: is it possible for an extension to convert a block to a proc and execute it later I found a good example of how to do this in hash.c // how i implemented in my extension code (blocks get priority) VALUE recvr, symb, proc; int symbid; rb_scan_args(argc, argv, "02&", &recvr, &symb, &proc) if(Qnil != proc) { recvr = proc; symbid = rb_intern("call"); // i actually cache this id in my init code } // stores the recvr and symbid on a context object and executes the async send // in the background ### ruby code, both ways work sock.send("HELLO", myclient, :send_complete) sock.send("HELLO") { puts "send complete" } One reason why I provide the explicit recvr, symbol version is because I haven't figured out how to do the following using block notation: class MyClient { @buffer def initialize() @buffer = "" end def recv_callback(sock, buffer) @buffer << buffer sock.recv(1024, self, :recv_callback) end end Basically I need the capability to continue issuing the recv/send calls and need to pass in the receiver of the completion when I issue the call. Is there something like? s.recv(1024) { s.recv(1024) this_block } On 2/23/06, Jacob Repp wrote: > I want to do this: > > puts "sending data" > sock.send("HELLO") { |nbytes| > puts "sent #{nbytes} bytes" > } > puts "processing io completions" > queue.process() # calls the above defined block > > I want to see the following outpout: > > sending data > processing io completions > sent 5 bytes > > Is this possible? > >