Example #1
0
func (this *Processor) Clear() {
	for kv := range this.pending.Iter() {
		kv.Val.(chan *Command) <- &Command{
			Key:    kv.Key,
			Action: ERROR,
			Body: dynamic.Build(
				"message", "Connection closed",
			),
		}
		this.pending.Remove(kv.Key)
	}
}
Example #2
0
func (this *Connection) respond(key string, resp interface{}, err error) {
	cmd := &Command{
		Key: key,
	}
	if err == nil {
		cmd.Action = RESPONSE
		cmd.Body = resp
	} else {
		if _, ok := err.(*DRSError); ok {
			cmd.Action = ERROR
			cmd.Body = dynamic.Build(
				"message", err.Error(),
			)
		} else {
			console.JSON("EXCEPTION", err)
			cmd.Action = EXCEPTION
			cmd.Body = dynamic.Build(
				"message", err.Error(),
			)
		}
	}
	this.Stream.Encode(cmd)
}