Exemplo n.º 1
0
// SendEvent pushes an event into the message queue for a particular vertex
func (obj *BaseRes) SendEvent(ev event.EventName, sync bool, activity bool) bool {
	// TODO: isn't this race-y ?
	if !obj.IsWatching() { // element has already exited
		return false // if we don't return, we'll block on the send
	}
	if !sync {
		obj.events <- event.Event{Name: ev, Resp: nil, Msg: "", Activity: activity}
		return true
	}

	resp := event.NewResp()
	obj.events <- event.Event{Name: ev, Resp: resp, Msg: "", Activity: activity}
	resp.ACKWait() // waits until true (nil) value
	return true
}
Exemplo n.º 2
0
// DoSend sends off an event, but doesn't block the incoming event queue. It can
// also recursively call itself when events need processing during the wait.
// I'm not completely comfortable with this fn, but it will have to do for now.
func (obj *BaseRes) DoSend(processChan chan event.Event, comment string) (bool, error) {
	resp := event.NewResp()
	processChan <- event.Event{event.EventNil, resp, comment, true} // trigger process
	select {
	case e := <-resp: // wait for the ACK()
		if e != nil { // we got a NACK
			return true, e // exit with error
		}

	case event := <-obj.events:
		// NOTE: this code should match the similar code below!
		//cuuid.SetConverged(false) // TODO ?
		if exit, send := obj.ReadEvent(&event); exit {
			return true, nil // exit, without error
		} else if send {
			return obj.DoSend(processChan, comment) // recurse
		}
	}
	return false, nil // return, no error or exit signal
}
Exemplo n.º 3
0
// DoSend sends off an event, but doesn't block the incoming event queue. It can
// also recursively call itself when events need processing during the wait.
// I'm not completely comfortable with this fn, but it will have to do for now.
func (obj *BaseRes) DoSend(processChan chan event.Event, comment string) (bool, error) {
	resp := event.NewResp()
	processChan <- event.Event{Name: event.EventNil, Resp: resp, Msg: comment, Activity: true} // trigger process
	e := resp.Wait()
	return false, e // XXX: at the moment, we don't use the exit bool.
	// XXX: this can cause a deadlock. do we need to recursively send? fix event stuff!
	//select {
	//case e := <-resp: // wait for the ACK()
	//	if e != nil { // we got a NACK
	//		return true, e // exit with error
	//	}
	//case event := <-obj.events:
	//	// NOTE: this code should match the similar code below!
	//	//cuid.SetConverged(false) // TODO: ?
	//	if exit, send := obj.ReadEvent(&event); exit {
	//		return true, nil // exit, without error
	//	} else if send {
	//		return obj.DoSend(processChan, comment) // recurse
	//	}
	//}
	//return false, nil // return, no error or exit signal
}
Exemplo n.º 4
0
// DoSend sends off an event, but doesn't block the incoming event queue.
func (obj *BaseRes) DoSend(processChan chan event.Event, comment string) (exit bool, err error) {
	resp := event.NewResp()
	processChan <- event.Event{Name: event.EventNil, Resp: resp, Activity: false, Msg: comment} // trigger process
	e := resp.Wait()
	return false, e // XXX: at the moment, we don't use the exit bool.
}