select
when timeout 1.seconds
puts 1
when timeout 2.seconds
puts 2
end
$ crystal run t.cr
2
Should this be a compile error? Also timeout + else? It doesn't make sense to have timeout with else or a second timeout.
@straight-shoota that's not so easy or elegant. In fact timeout is not a keyword, It's a method call. Any *_select_action that returns an implementation of SelectAction can participate in the select statement.
I think this is low priority. I think at least two timeouts could be caught at runtime, maybe checking if the fiber's timeout is already set. Not sure.
I think at least it should work as expected. 1 second is less than 2 seconds. It should trigger first! 馃槅
I guess that makes sense. Those timeout values could come from variables and you'd expect the smaller one to trigger first.
@waj
In fact timeout is not a keyword, It's a method call.
It's kind of both. There's not timeout method. The compiler expands timeout to timeout_select_action. So it could notice that having two timeout calls in the same select doesn't make sense. Of course this would mean to have some semantic interpretation of these select actions in the compiler. Maybe we should try to avoid that. I guess there is not a huge benefit from making it a compile time error.
It could be considered as a runtime error.
Just a note, not something that makes sense: you could theoretically redefine timeout_select_action in a scope and give it another meaning.
Yes, maybe just don't overwrite the timeout event if the current one is lower, and in combination with #8832 ignore negative values.
Most helpful comment
I think at least it should work as expected. 1 second is less than 2 seconds. It should trigger first! 馃槅