rustler icon indicating copy to clipboard operation
rustler copied to clipboard

yielding api

Open devsnek opened this issue 1 year ago • 3 comments

something i'm experimenting with in https://github.com/devsnek/jsont/pull/1

devsnek avatar Feb 29 '24 02:02 devsnek

Are you still working on this or did you hit a roadblock? I'd be interested in exploring a high-level variant of this using Rust's async functions.

filmor avatar Jul 07 '24 14:07 filmor

I no longer work at the company where I was working on this. Async functions would be cool and I experimented with it a bit. The main issue is that it's difficult to provide an Env to async functions correctly. I tried some hacks like a fake env that implements deref to get the real env but I'm fairly sure it's not actually possible in safe rust to prevent the reference from being held across await points. It is doable in generators though, and I at one point had something working where env references are passed in via yield. the only annoyance with this is that you still can't hold any values across suspend points, you need to somehow interface with rust and put all the values it captures into the reschedule arguments and that's not possible. So I ended up with the much simpler model you see here.

devsnek avatar Jul 07 '24 14:07 devsnek

The only safe way is to copy all terms to a process-independent environment and use the terms from that one. But that should actually work across awaits, right?

filmor avatar Aug 30 '24 12:08 filmor