Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Provide wrenGetCurrentFiber() API #103

Closed
joshgoebel opened this issue May 2, 2021 · 2 comments
Closed

[RFC] Provide wrenGetCurrentFiber() API #103

joshgoebel opened this issue May 2, 2021 · 2 comments

Comments

@joshgoebel
Copy link
Contributor

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)

@ChayimFriedman2
Copy link

I think this issue should target the core repository, since we're talking about adding a function there.

@joshgoebel
Copy link
Contributor Author

That was my intent, and my mistake. Closing and will re-open there. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants