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 #1003

Open
joshgoebel opened this issue May 2, 2021 · 4 comments
Open

[RFC] Provide wrenGetCurrentFiber() API #1003

joshgoebel opened this issue May 2, 2021 · 4 comments

Comments

@joshgoebel
Copy link

joshgoebel commented May 2, 2021

Suggest adding:

void wrenGetCurrentFiber(WrenVM* vm, int slot)

This would take Fiber.current and place a reference to it into the requested slot.


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 wren-lang/wren-cli#102 (comment)

@ChayimFriedman2
Copy link
Contributor

Just noting that the signature should probably be:

void wrenGetCurrentFiber(WrenVM* vm, int slot)

@mhermier
Copy link
Contributor

mhermier commented May 5, 2021

Trivially correct.

@joshgoebel
Copy link
Author

Would a PR for this be welcome?

@graphitemaster
Copy link

Bumping this since I could also use it for the same purpose, implementing async/await event loop model like JS in Wren

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

4 participants