[forwardport] refactor(oonimkall): merge internal/task into oonimkall (#617) (#618)

This diff forward ports bc4b9f1ea89158bfa7b7a80ae59a90b43c784ed2 to `master`.

See https://github.com/ooni/probe/issues/1903
This commit is contained in:
Simone Basso 2021-11-26 20:21:42 +01:00 committed by GitHub
commit ee5be24900
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 182 additions and 194 deletions

View file

@ -45,7 +45,6 @@ import (
"github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/runtimex"
"github.com/ooni/probe-cli/v3/pkg/oonimkall/internal/tasks"
)
// Task is an asynchronous task running an experiment. It mimics the
@ -63,13 +62,13 @@ type Task struct {
cancel context.CancelFunc
isdone *atomicx.Int64
isstopped *atomicx.Int64
out chan *tasks.Event
out chan *event
}
// StartTask starts an asynchronous task. The input argument is a
// serialized JSON conforming to MK v0.10.9's API.
func StartTask(input string) (*Task, error) {
var settings tasks.Settings
var settings settings
if err := json.Unmarshal([]byte(input), &settings); err != nil {
return nil, err
}
@ -79,12 +78,12 @@ func StartTask(input string) (*Task, error) {
cancel: cancel,
isdone: &atomicx.Int64{},
isstopped: &atomicx.Int64{},
out: make(chan *tasks.Event, bufsiz),
out: make(chan *event, bufsiz),
}
go func() {
defer close(task.out)
defer task.isstopped.Add(1)
tasks.Run(ctx, &settings, task.out)
run(ctx, &settings, task.out)
}()
return task, nil
}