Fwd: [Iowa-general] Async again

Kirk Haines khaines at enigo.com
Wed Oct 6 17:06:48 EDT 2004


On Wed, 6 Oct 2004 13:23:56 -0700, Mark Probert wrote

>  Wait.html
> 
> 	<body onload="doLoad()">
> 	<a oid="reload" id="inelegant_reload_hack" style="visibility: 
hidden"></a>
> 
>  Wait.iwa
> 
>   reload()
>    f = process_finished?
>    load_results if f
>   end
> 
>   load_results()
>     setup_results
>     create newPage
>     yield newPage
>   end
> 
> So, I get a "no block given" at the yield even if the page a very 
> basic one (no dynamic data).
> 
> Any ideas, Kirk?

Yep.  You are getting bitten by Ruby, there.

When a method like reload() is called, a block is passed to it.  That way 
when you call yield, there is a block to recieve the object being yielded.

However, when you call load_results(), the block does not go with 
load_results.  So, when you call yield in load_results, there is no block to 
receive the object.

reload()
  f = process_finished?
  yield(load_results) if f
end
 
load_results()
  setup_results
  create newPage
  newPage
end

That's probably the easiest way to get what you are doing to work.

The other way would be to explicitly assign the block to a variable and pass 
it on to load_results yourself:

def reload(&my_block)
  f = process_finished?
  load_results {|x| my_block.call(x)} if f
end

def load_results()
  setup_results
  create newPage
  yield newPage
end

Something like that would work, but I think it's less clear than the first
example, personally.


I hope that helps,

Kirk


More information about the Iowa-general mailing list