[RFC] Provide wrenGetCurrentFiber() API
joshgoebel opened this issue · comments
This would be helpful for schedulers in general but more specifically would solve this problem of always needing Fiber.current
inside C for callbacks - but never having it... resulting in code like:
Scheduler.await_ { startTimer_(milliseconds, Fiber.current) }
It would be desirable to be able to simplify:
Scheduler.await_ { startTimer_(milliseconds) }
This can be done now fairly easily by accessing private API but would be fragile in the future and subject to breakage:
WrenHandle* getFiberCurrent(WrenVM* vm) {
return wrenMakeHandle(vm, OBJ_VAL(vm->fiber));
}
It's also possible for the Scheduler to just push this information down into C itself:
static await_(fn) {
preserveFiberCurrent_(Fiber.current)
fn.call()
return Scheduler.runNextScheduled_()
}
Having the API already available in C to achieve this seems a much more elegant solution though. If this would be welcome I can create a PR.
Original context:
Another thing we can do, however, is to expose a
wrenGetCurrentFiber()
method in the API (because it's useful for schedulers in general).
Originally posted by @ChayimFriedman2 in #102 (comment)
I think this issue should target the core repository, since we're talking about adding a function there.
That was my intent, and my mistake. Closing and will re-open there. :-)