async-interop / event-loop

An event loop interface for interoperability in PHP.
MIT License
170 stars 9 forks source link

Specify error cases #134

Open kelunik opened 7 years ago

kelunik commented 7 years ago

Currently we do not specify error cases apart from invalid watcher IDs, e.g. what happens on a negative or 0 interval for timers, what happens on a wrong type there, etc.

bwoebi commented 7 years ago

I don't think we need to specify wrong types.

It makes sense to explicitly specify negative integers being unspecified.

(A zero interval for timers is pretty straightforward … it gets executed again after 0 time, i.e. in the next tick - which is implied by the current wording...)

kelunik commented 7 years ago

It makes sense to explicitly specify negative integers being unspecified.

Why does this make sense?!

bwoebi commented 7 years ago

Looks like we should also include 0 here, the underlying loop backends don't seem to be able to handle that well.

joshdifabio commented 7 years ago

I think it would be good if all loop implementations handled these edge cases the same way, including numeric strings such as '1' being passed as delays/intervals. We don't want applications breaking when someone swaps loop implementations because the unspecified behaviour is handled different by different loops. Perhaps we could add some logic to Driver which validates and sanitises inputs to ensure that all drivers treat these edge cases the same way.

bwoebi commented 7 years ago

@kelunik Hmm, doesn't make much sense to have it completely unspecified - I think we should specify that they MUST throw a \Throwable|\Exception (but not what type of Throwable exactly they shall throw).

bwoebi commented 7 years ago

@joshdifabio That's not an inherently bad idea, but it will have quite a footprint (e.g. extra function call) [also, not all functions receive args, so we'd have some functions directly being public API, others being protected…] … I'm not too much a fan of it.