Will it be possible to serialize state and limit execution time?
Summary
Will this extension support non-blocking operation and state serialization?
Additional details
It can in many cases be helpful to run code for a certain number of instructions, or milliseconds before execution is preemptively halted.
This can be useful for example in event loop environments such as swoole or ReactPHP.
To support this, it would be necessary that wasm methods could return a special "WasmHalted" object. This object could represent that execution was halted due to timeout, waiting for IO, or it could represent a request for opening a resource such as a file.
$delayed = $instance->sum(1, 2);
$delayed->run(1000); // 1000 instructions
$s = serialize($delayed);
$delayed = $instance->resume(unserialize($s)) ;
while(!$delayed->done()) {
$delayed->run(1000):
}
$delayed->result(); // done
I would love if this object could be serialized and resumed. Sure, the serialized object can become quite large, if the wasm binary uses a lot of memory but that would be my problem.
So far, the Wasmer runtime (the underlying WebAssembly runtime) supports gas metering, but I don't think it is what you want. I think a first step is https://github.com/wasmerio/wasmer/issues/480. This is implemented, but not the C API doesn't handle it for the moment. We can work on it though.