1
0
Fork 0

baggage handling system implementation

main^2
Sebastian Steger 2026-04-21 09:49:30 +00:00
parent 89e3c3eab9
commit 5c1338301b
1 changed files with 26 additions and 5 deletions

View File

@ -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
}