Canonicalise gremlin receiver names

This commit is contained in:
kortschak 2014-06-28 21:56:42 +09:30
parent 3831aad364
commit 5a1a7259c8

View file

@ -68,39 +68,39 @@ type GremlinResult struct {
actualResults *map[string]graph.TSVal actualResults *map[string]graph.TSVal
} }
func (g *Session) ToggleDebug() { func (s *Session) ToggleDebug() {
g.debug = !g.debug s.debug = !s.debug
} }
func (g *Session) GetQuery(input string, output_struct chan map[string]interface{}) { func (s *Session) GetQuery(input string, output_struct chan map[string]interface{}) {
defer close(output_struct) defer close(output_struct)
g.queryShape = make(map[string]interface{}) s.queryShape = make(map[string]interface{})
g.lookingForQueryShape = true s.lookingForQueryShape = true
g.env.Run(input) s.env.Run(input)
output_struct <- g.queryShape output_struct <- s.queryShape
g.queryShape = nil s.queryShape = nil
} }
func (g *Session) InputParses(input string) (graph.ParseResult, error) { func (s *Session) InputParses(input string) (graph.ParseResult, error) {
script, err := g.env.Compile("", input) script, err := s.env.Compile("", input)
if err != nil { if err != nil {
return graph.ParseFail, err return graph.ParseFail, err
} }
g.script = script s.script = script
return graph.Parsed, nil return graph.Parsed, nil
} }
func (g *Session) SendResult(result *GremlinResult) bool { func (s *Session) SendResult(result *GremlinResult) bool {
if g.limit >= 0 && g.limit == g.count { if s.limit >= 0 && s.limit == s.count {
return false return false
} }
if g.doHalt { if s.doHalt {
return false return false
} }
if g.currentChannel != nil { if s.currentChannel != nil {
g.currentChannel <- result s.currentChannel <- result
g.count++ s.count++
if g.limit >= 0 && g.limit == g.count { if s.limit >= 0 && s.limit == s.count {
return false return false
} else { } else {
return true return true
@ -111,46 +111,46 @@ func (g *Session) SendResult(result *GremlinResult) bool {
var halt = errors.New("Query Timeout") var halt = errors.New("Query Timeout")
func (g *Session) runUnsafe(input interface{}) (otto.Value, error) { func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
g.doHalt = false s.doHalt = false
defer func() { defer func() {
if caught := recover(); caught != nil { if caught := recover(); caught != nil {
if caught == halt { if caught == halt {
g.err = halt s.err = halt
return return
} }
panic(caught) // Something else happened, repanic! panic(caught) // Something else happened, repanic!
} }
}() }()
g.env.Interrupt = make(chan func(), 1) // The buffer prevents blocking s.env.Interrupt = make(chan func(), 1) // The buffer prevents blocking
if g.timeoutSec != -1 { if s.timeoutSec != -1 {
go func() { go func() {
time.Sleep(g.timeoutSec * time.Second) // Stop after two seconds time.Sleep(s.timeoutSec * time.Second) // Stop after two seconds
g.doHalt = true s.doHalt = true
if g.env != nil { if s.env != nil {
g.env.Interrupt <- func() { s.env.Interrupt <- func() {
panic(halt) panic(halt)
} }
g.env = g.emptyEnv s.env = s.emptyEnv
} }
}() }()
} }
return g.env.Run(input) // Here be dragons (risky code) return s.env.Run(input) // Here be dragons (risky code)
} }
func (g *Session) ExecInput(input string, out chan interface{}, limit int) { func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
defer close(out) defer close(out)
g.err = nil s.err = nil
g.currentChannel = out s.currentChannel = out
var err error var err error
var value otto.Value var value otto.Value
if g.script == nil { if s.script == nil {
value, err = g.runUnsafe(input) value, err = s.runUnsafe(input)
} else { } else {
value, err = g.runUnsafe(g.script) value, err = s.runUnsafe(s.script)
} }
if err != nil { if err != nil {
out <- &GremlinResult{metaresult: true, out <- &GremlinResult{metaresult: true,
@ -163,9 +163,9 @@ func (g *Session) ExecInput(input string, out chan interface{}, limit int) {
val: &value, val: &value,
actualResults: nil} actualResults: nil}
} }
g.currentChannel = nil s.currentChannel = nil
g.script = nil s.script = nil
g.env = g.emptyEnv s.env = s.emptyEnv
return return
} }