-
Notifications
You must be signed in to change notification settings - Fork 7
/
example_test.go
44 lines (37 loc) · 873 Bytes
/
example_test.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
42
43
44
package slaves_test
import (
"fmt"
"github.com/themester/GoSlaves"
"io/ioutil"
"os"
)
func ExampleSlavePool_SendWorkTo() {
sp := slaves.MakePool(2)
sp.Open(func(obj interface{}) interface{} {
fmt.Println(obj)
return nil
}, nil)
defer sp.Close()
sp.Slaves[0].Type = "ProcessPiDecimals"
sp.Slaves[1].Type = "MakeCake"
sp.SendWorkTo("MakeCake", "Make me a cake plsssss")
sp.SendWorkTo("ProcessPiDecimals", "Execute python and kill my motherboard")
}
// Simple slave pool example
func ExampleMakePool() {
sp := slaves.MakePool(10)
if err := sp.Open(func(obj interface{}) interface{} {
fmt.Println(obj.(string))
return nil
}, nil); err != nil {
panic(err)
}
defer sp.Close()
files, err := ioutil.ReadDir(os.TempDir())
if err == nil {
fmt.Println("Files in temp directory:")
for i := range files {
sp.SendWork(files[i].Name())
}
}
}