Skip to content

Commit

Permalink
Solve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelsr committed Aug 13, 2023
2 parents 727f166 + 9317d46 commit bb1b9fd
Show file tree
Hide file tree
Showing 13 changed files with 962 additions and 105 deletions.
4 changes: 2 additions & 2 deletions api/process.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ $Go.import("github.com/wetware/pkg/api/process");
interface Executor {
# Executor has the ability to create and run WASM processes given the
# WASM bytecode.
exec @0 (bytecode :Data, bootstrapClient :Capability) -> (process :Process);
exec @0 (bytecode :Data, ppid :UInt32, bootstrapClient :Capability) -> (process :Process);
# Exec creates an runs a process from the provided bytecode. Optionally, a
# capability can be passed through the `cap` parameter. This capability will
# be available at the process bootContext.
#
# The Process capability is associated to the created process.
execCached @1 (cid :Text, bootstrapClient :Capability) -> (process :Process);
execCached @1 (cid :Text, ppid :UInt32, bootstrapClient :Capability) -> (process :Process);
# Same as Exec, but the bytecode is directly from the BytecodeRegistry.
# Provides a significant performance improvement for medium to large
# WASM streams.
Expand Down
150 changes: 84 additions & 66 deletions api/process/process.capnp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 28 additions & 4 deletions cap/csp/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,33 @@ func (ex Executor) Release() {
capnp.Client(ex).Release()
}

func (ex Executor) Exec(ctx context.Context, src []byte) (Proc, capnp.ReleaseFunc) {
f, release := api.Executor(ex).Exec(ctx, func(ps api.Executor_exec_Params) error {
return ps.SetBytecode(src)
})
// Exec spawns a new process from WASM bytecode bc. If the caller is a WASM process
// spawned in this same executor, it should use its PID as ppid to mark the
// new process as a subprocess.
func (ex Executor) Exec(ctx context.Context, bc []byte, ppid uint32, client capnp.Client) (Proc, capnp.ReleaseFunc) {
f, release := api.Executor(ex).Exec(ctx,
func(ps api.Executor_exec_Params) error {
if err := ps.SetBytecode(bc); err != nil {
return err
}

ps.SetPpid(ppid)
return ps.SetBootstrapClient(client)
})
return Proc(f.Process()), release
}

// ExecFromCache behaves the same way as Exec, but expects the bytecode to be already
// cached at the executor.
func (ex Executor) ExecFromCache(ctx context.Context, cid string, ppid uint32, client capnp.Client) (Proc, capnp.ReleaseFunc) {
f, release := api.Executor(ex).ExecCached(ctx,
func(ps api.Executor_execCached_Params) error {
if err := ps.SetCid(cid); err != nil {
return err
}

ps.SetPpid(ppid)
return ps.SetBootstrapClient(client)
})
return Proc(f.Process()), release
}
24 changes: 19 additions & 5 deletions cap/csp/proc.go → cap/csp/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@ func (p Proc) Release() {
capnp.Client(p).Release()
}

// func (p Proc) Kill(ctx context.Context) error {
// f, release := api.Process(p).Kill(ctx, nil)
// defer release()
// Kill a process and any sub processes it might have spawned.
func (p Proc) Kill(ctx context.Context) error {
f, release := api.Process(p).Kill(ctx, nil)
defer release()

select {
case <-f.Done():
case <-ctx.Done():
}

if ctx.Err() != nil {
return ctx.Err()
}

// return casm.Future(f).Await(ctx)
// }
_, err := f.Struct()
if err != nil {
return err
}
return nil
}

func (p Proc) Wait(ctx context.Context) error {
f, release := api.Process(p).Wait(ctx, nil)
Expand Down
Loading

0 comments on commit bb1b9fd

Please sign in to comment.