From: Ned Konz Date: 2002-06-28T23:04:16+09:00 Subject: Re: Transparent asynchronous execution On Friday 28 June 2002 03:38 am, Max Maischein wrote: > For the implementation, almost everything seems to go smoothly > except for the delegation part. Before the result becomes > available, I want the Promise class to block the calling thread on > every message sent to it (this could maybe done by overriding > Object#send), and after the result becomes available, I want the > Promise to send all messages to the result (i.e., I want the > Promise to be as transparent to the caller as possible). I've > looked at the Delegator class, but this class wants to know which > object it delegates to - the Promise dosen't know which object it > will delegate to until the result becomes available - how can I > approach this problem ? Easy: don't make Promises transparent. i.e. require that their user send them a particular message (say :value here): foo = Promise(1,2,3) { |a,b,c| r1 = some_function_that_takes_long_to_compute( a,b,c ) r2 = some_other_function_that_takes_even_longer( r1 ) r2 } bar = a_third_function_that_takes_long_to_compute( 1,2,3 ) print calculate_statistics( bar, foo.value ) This way, Promise.value can be defined as something like: def value @thread.join # blocks if thread is not done; # thread puts result into @result @result end -- Ned Konz http://bike-nomad.com GPG key ID: BEEA7EFE