diff --git a/go/06-airport/airport/baggageHandlingSystem.go b/go/06-airport/airport/baggageHandlingSystem.go index 9c81002..a30fcec 100644 --- a/go/06-airport/airport/baggageHandlingSystem.go +++ b/go/06-airport/airport/baggageHandlingSystem.go @@ -1,6 +1,7 @@ package airport import ( + "fmt" "time" ) @@ -11,7 +12,7 @@ type BaggageProcessor interface { type BaggageHandlingSystem struct { processingTime time.Duration sinks map[FlightNumber]BaggageProcessor - //TODO: extend + lostBaggage chan LostBaggage } type LostBaggage struct { @@ -26,19 +27,39 @@ func NewBaggageHandlingSystem(processingTime time.Duration, sinks map[FlightNumb return BaggageHandlingSystem{ processingTime: processingTime, sinks: sinks, + lostBaggage: make(chan LostBaggage), } } func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error { - //TODO: implement + sink, ok := bhs.sinks[fn] + if !ok { + return fmt.Errorf("invalid flight %v", fn) + } + + go func() { + time.Sleep(bhs.processingTime) + if err := sink.ProcessBaggage(fn, b); err != nil { + bhs.lostBaggage <- LostBaggage{b, fn, err} + } + }() + return nil + } func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage { - //TODO: implement - return nil + lostBaggage := []LostBaggage{} + for { + select { + case lb := <-bhs.lostBaggage: + lostBaggage = append(lostBaggage, lb) + default: + return lostBaggage + } + } } func (bhs *BaggageHandlingSystem) Start() { - //TODO: implement + }