Effectively final

Rémi Forax forax at univ-mlv.fr
Sat Jul 30 06:18:25 PDT 2011


On 07/30/2011 11:32 AM, Tim Fox wrote:
> Consider another example written in Ruby:
>
> def foo(socket)
>     timed_out = false
>     system.set_timeout(100) { timed_out = true }
>     socket.on_data{ puts "Got data" if !timed_out}
> end
>
> This case would be overkill to use your technique in Java (an
> AtomicBoolean would do), but then I have to explain to the user why they
> have to use an AtomicBoolean when there's only one thread executing it:(

Java 8 is more verbose, but not much:

void foo(AsyncSocket socket) {
   int[] timeout = {false };
   AsyncSystem.setTimeout(100, #{ timeout[0] = true; });
   socket.onData(#{ socket -> if (!timeout[0]) socket.write("Got data"); 
});
}

BTW, why your framework doesn't manage the timeout by itself
instead of letting the users create bad and sluggish webserver because
they forget to set a timeout.

Rémi



More information about the lambda-dev mailing list