onReceive method

  1. @override
void onReceive(
  1. LocalityEvent localityEvent
)
override

React to events being thrown. Use switch case on the localityEvent.event

Implementation

@override
void onReceive(LocalityEvent localityEvent) {
  if ( !waiterInitialized ) {
    List<EventWaitInstruction> instructions = getEventWaitInstructions();
    for(int i = 0; i < instructions.length; i++) {
      eventWaiter.register(instructions[i].event, instructions[i].waitsForEvent, instructions[i].traitName, 2);
    }

    waiterInitialized = true;
  }
  eventWaiter.traitUp(localityEvent.event, localityEvent.payload);

  if ( eventWaiter.passes(localityEvent.event, localityEvent.payload) ) {
    onRelease(localityEvent);
  } else {
    waitingEvents.add(localityEvent);
  }

  for(int i = 0; i < waitingEvents.length; i++) {
    if ( eventWaiter.passes(waitingEvents[i].event, waitingEvents[i].payload) ) {
      waitingEvents.removeAt(i);
      onRelease(waitingEvents[i]);
    }
  }
}