tetratelabs / wazero

wazero: the zero dependency WebAssembly runtime for Go developers
https://wazero.io
Apache License 2.0
4.86k stars 255 forks source link

Add Runtime.Close #382

Closed codefromthecrypt closed 2 years ago

codefromthecrypt commented 2 years ago

I noticed that users of wazero including ourselves often have a single imported module (WASI) and the one they made. To close requires them closing those in reverse order. I wonder if we can't have Runtime.Close which can do the same?

An alternative would be if WASI could be special cased to never need closing. I don't know off the top of my head if we could pre-compile any glue needed and/or use offsets based on a go:embed FS or any other tricks to make WASI be safe to always be around.

codefromthecrypt commented 2 years ago

this helps when a caller has a bunch of host modules, and prevents bookkeeping like this:

    if wapc := m.wapc; wapc != nil {
        _ = wapc.Close(ctx)
        m.wapc = nil
    }

    if env := m.env; env != nil {
        _ = env.Close(ctx)
        m.env = nil
    }

    if wasi := m.wasi; wasi != nil {
        _ = wasi.Close(ctx)
        m.wasi = nil
    }
codefromthecrypt commented 2 years ago

@anuraaga @mathetake we probably need to decide if this will be an API or not. If it will, we should block 1.0 on it as it affects how people manage lifecycle.

anuraaga commented 2 years ago

+1 on Runtime.Close, was hoping for it when initializing multiple modules.

mathetake commented 2 years ago

+1

codefromthecrypt commented 2 years ago

ok I'll add this to the blocker list