Conversation
It actually looks like (at least from the libuv perspective) you can issue a timer_stop followed by timer_again, and it will use the callback currently registered. This seems beneficial to me from the perspective of a "pause" feature. Bad naming on the libuv side of things, but it seems like a useful feature to have. As far as implementing it in JS, we would probably have to just stop the timer and start a new one. We could also do the same in Koka for a pause feature (or set a boolean flag not to call a user callback), but it seems to be a waste of cycles in Koka if libuv already supports it, where JS we have do it either way. Maybe this is just me justifying keeping the libuv stuff, but I imagine Koka as a C first language, and JS second, and I feel like people would appreciate whatever is available in C (and be okay with an error in JS if it is not available). We could probably add it later though after requests.
I'm fine with this. See the note below about the ordering of fields though.
Sounds good to me.
Sounds good.
I hadn't thought about the generic functions for dropping callbacks. We could probably still do so if given a reference to the uv struct it is built from (as a macro generated function). Its a tradeoff of how often are you accessing callbacks versus accessing the uv struct -> if you access the struct frequently to call uv apis then it is a cast (no-op) the way I have the fields ordered, which is what I was going for. If the struct often accesses the callback, then maybe a more predictable offset would be useful for CPU branch prediction -> but it is predictable anyways if you are using a lot of the same libuv handles. |
It exists in UV so obviously there are use cases out there which we'll likely want to support eventually, but I'd prefer to keep that complexity out of the
For clarity here's the generic drop I wrote:
TBH I haven't considered the efficiency here, just developer ergonomics (the less macros & casts I have to deal with the better). I wouldn't have thought access costs would play much of a part in most UV ops though compared to IO and allocations. Happy to defer this decision though. |
The first commit has some timer API changes:
The second commit is nonfunctional cleanups which I think are also useful, and removes some differences between this branch and my
v2branch:v2branch I have largely replaced these macros with functions for clarity, but we don't need either just yet.uv_##uv_hnd_tp##_as_kk,kk_##uv_hnd_tp##_box) for some added safety.Remaining differences
One main difference remains that in my
v2branch, the generated structures all have a common prefix:Whereas here, every struct has a
callbackbut its offset within the struct is different per UV type, because the (differently-sized) uv handle is first member of the struct:This means we can't write generic functions to e.g. take / drop the callback for any kk_uv wrapper struct. So I think we should rearrange these fields, but I haven't done that yet (there's no need with just one struct type, but I think we'll want it later).