Skip to content

Commit

Permalink
Merge pull request #267 from mikedewar/master
Browse files Browse the repository at this point in the history
make pack work
  • Loading branch information
nikhan committed Feb 19, 2014
2 parents 48b70db + 7c563a4 commit 6405105
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions blocks/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package blocks

import (
"container/heap"
"github.com/nytlabs/gojee"
"log"
"strings"
"time"
)

Expand All @@ -13,12 +13,12 @@ import (
func Pack(b *Block) {

type bunchRule struct {
Branch string
EmitAfter int
Path string
EmitAfter string
}

var rule *bunchRule
var branch []string
var tree *jee.TokenTree

after := time.Duration(0)
waitTimer := time.NewTimer(100 * time.Millisecond)
Expand All @@ -39,8 +39,22 @@ func Pack(b *Block) {
rule = &bunchRule{}
}
unmarshal(msg, rule)
after = time.Duration(rule.EmitAfter) * time.Second
branch = strings.Split(rule.Branch, ".")
token, err := jee.Lexer(rule.Path)
if err != nil {
log.Println(err.Error())
break
}
tree, err = jee.Parser(token)
if err != nil {
log.Println(err.Error())
break
}

after, err = time.ParseDuration(rule.EmitAfter)
if err != nil {
log.Println(err.Error())
break
}
case msg := <-b.Routes["get_rule"]:
if rule == nil {
marshal(msg, &bunchRule{})
Expand All @@ -51,14 +65,19 @@ func Pack(b *Block) {
if rule == nil {
break
}
if tree == nil {
break
}

id, err := Get(msg.Msg, branch...)
id, err := jee.Eval(tree, msg.Msg)
if err != nil {
log.Println(err.Error())
break
}
idStr, ok := id.(string)
if !ok {
log.Fatal("type assertion failed")
}
if err != nil {
log.Fatal(err.Error())
log.Println("could not assert id to string")
break
}
if len(bunches[idStr]) > 0 {
bunches[idStr] = append(bunches[idStr], msg.Msg)
Expand Down
Binary file added examples/helloWorld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6405105

Please sign in to comment.