persistence: is it a bad idea to keep a javascript function?

Many functions can not be persisted easily because they access variables from external environments (they are closures). A persistence mechanism would have to pick up that context as well.

If the function can change In this context, it will not be possible to keep the function + context in one process and to restore it in another process, since the secondary effects of executing the function would not be visible in the first process.

The main problem is that the code is not purely functional but it can have side effects. Eliminating side effects would make a function safe to suspend, but JavaScript does not offer any language level guarantee that this is safe.

In your case, it is likely that the solution does not persist in the context of a function, but encodes the promises as events that can be stored explicitly: then you can try again to execute some code until an exit event is generated. Modeling something explicitly is often a sensible approach when the main language can not express some concept directly.