Add context

This commit adds and passes context around to (almost) every function.
This allows cancelling (almost) every function call globally.
This commit is contained in:
Tom Wiesing 2022-11-28 13:30:08 +01:00
parent 996ecb9f80
commit 3455f491ca
No known key found for this signature in database
104 changed files with 836 additions and 511 deletions

View file

@ -1,6 +1,7 @@
package php
import (
"context"
_ "embed"
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
@ -14,11 +15,12 @@ import (
// See [PHPServer].
func (php *PHP) NewServer() *phpx.Server {
return &phpx.Server{
Context: context.Background(),
Executor: phpx.SpawnFunc(php.spawn),
}
}
func (php *PHP) spawn(str stream.IOStream, code string) error {
_, err := php.Barrel.Shell(str, "-c", shellescape.QuoteCommand([]string{"drush", "php:eval", code}))
func (php *PHP) spawn(ctx context.Context, str stream.IOStream, code string) error {
_, err := php.Barrel.Shell(ctx, str, "-c", shellescape.QuoteCommand([]string{"drush", "php:eval", code}))
return err
}