-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.go
41 lines (35 loc) · 852 Bytes
/
process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package jasper
import (
"context"
"fmt"
"github.com/tychoish/jasper/options"
)
// NewProcess is a factory function which constructs a local Process outside
// of the context of a manager.
func NewProcess(ctx context.Context, opts *options.Create) (Process, error) {
var (
proc Process
err error
)
if err = opts.Validate(); err != nil {
return nil, (err)
}
switch opts.Implementation {
case options.ProcessImplementationBlocking:
proc, err = NewBlockingProcess(ctx, opts)
if err != nil {
return nil, err
}
case options.ProcessImplementationBasic:
proc, err = NewBasicProcess(ctx, opts)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("cannot create '%s' type of process", opts.Implementation)
}
if !opts.Synchronized {
return proc, nil
}
return &synchronizedProcess{proc: proc}, nil
}