Add output to persisted engine run, add code docs

This commit is contained in:
lash
2023-04-13 09:38:35 +01:00
parent 1844415ae9
commit 12ff703bc9
4 changed files with 41 additions and 10 deletions

View File

@@ -9,6 +9,16 @@ import (
"git.defalsify.org/festive/resource"
)
// RunPersisted performs a single vm execution from client input using a persisted state.
//
// State is first loaded from storage. The vm is initialized with the state and executed. The new state is then saved to storage.
//
// The resulting output of the execution will be written to the provided writer.
//
// The state is identified by the SessionId member of the Config. Before first execution, the caller must ensure that an
// initialized state actually is available for the identifier, otherwise the method will fail.
//
// It will also fail if execution by the underlying Engine fails.
func RunPersisted(cfg Config, rs resource.Resource, pr persist.Persister, input []byte, w io.Writer, ctx context.Context) error {
err := pr.Load(cfg.SessionId)
if err != nil {
@@ -24,5 +34,5 @@ func RunPersisted(cfg Config, rs resource.Resource, pr persist.Persister, input
return err
}
}
return nil
return en.WriteResult(w, ctx)
}