Initial commit

This commit is contained in:
2014-08-24 19:56:55 +07:00
commit 509f281f72
11 changed files with 337 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
package aggregator
import (
"fmt"
"code.google.com/p/go.net/context"
"github.com/localhots/yeast/tools"
"github.com/localhots/yeast/units/power"
)
func Call(ctx context.Context) context.Context {
results := []string{}
tools.SyncronizeParallelChain(ctx, func(ctx context.Context) {
r := ctx.Value("power_result").(power.PowerResult)
results = append(results, fmt.Sprintf("%d ^ %d = %d", r.Num, r.Power, r.Result))
})
ctx = context.WithValue(ctx, "power_results", results)
return ctx
}
+17
View File
@@ -0,0 +1,17 @@
package input
import (
"flag"
"code.google.com/p/go.net/context"
)
func FromFlag(ctx context.Context) context.Context {
var num int
flag.IntVar(&num, "num", 0, "Pass this number")
flag.Parse()
ctx = context.WithValue(ctx, "num", num)
return ctx
}
+20
View File
@@ -0,0 +1,20 @@
package logger
import (
"fmt"
"code.google.com/p/go.net/context"
)
func Call(ctx context.Context) context.Context {
results := ctx.Value("power_results").([]string)
id := ctx.Value("id").(string)
fmt.Println("Calculation result", id)
fmt.Println("Power results are:")
for _, r := range results {
fmt.Println(r)
}
return ctx
}
+37
View File
@@ -0,0 +1,37 @@
package power
import (
"code.google.com/p/go.net/context"
)
type (
PowerResult struct {
Num int
Power int
Result int
}
)
func Power2(ctx context.Context) context.Context {
v := ctx.Value("num").(int)
res := PowerResult{Num: v, Power: 2, Result: v * v}
ctx = context.WithValue(ctx, "power_result", res)
return ctx
}
func Power3(ctx context.Context) context.Context {
v := ctx.Value("num").(int)
res := PowerResult{Num: v, Power: 3, Result: v * v * v}
ctx = context.WithValue(ctx, "power_result", res)
return ctx
}
func Power5(ctx context.Context) context.Context {
v := ctx.Value("num").(int)
res := PowerResult{Num: v, Power: 5, Result: v * v * v * v * v}
ctx = context.WithValue(ctx, "power_result", res)
return ctx
}
+15
View File
@@ -0,0 +1,15 @@
package sleep
import (
"fmt"
"time"
"code.google.com/p/go.net/context"
)
func Call(ctx context.Context) context.Context {
fmt.Println("Going into sleep")
time.Sleep(5 * time.Second)
fmt.Println("Woke up")
return ctx
}
+12
View File
@@ -0,0 +1,12 @@
package uuid
import (
"code.google.com/p/go-uuid/uuid"
"code.google.com/p/go.net/context"
)
func Call(ctx context.Context) context.Context {
ctx = context.WithValue(ctx, "id", uuid.New())
return ctx
}