Documentation
¶
Overview ¶
Package shop implements the sleeping barber problem. There is one barber in the barber shop, one barber chair and n chairs for waiting customers. If there are no customers, the barber sits down in the barber chair and takes a nap. An arriving customer must wake the barber. Subsequent arriving customers take a waiting chair if any are empty or leave if all chairs are full.
Have the ability to close the shop even if new customers are entering. Customers looking for a chair should run on their own goroutine.
Task: Change EnterCustomer so a customer can wait for a specified amount of time for a chair to open up.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrShopClosed is returned when the shop is closed. ErrShopClosed = errors.New("shop closed") // ErrNoChair is returned when all the chairs are occupied. ErrNoChair = errors.New("no chair available") )
Functions ¶
This section is empty.
Types ¶
type Shop ¶
type Shop struct {
// contains filtered or unexported fields
}
Shop represents the barber's shop which contains chairs for customers that customers can occupy and the barber can service. The shop can be closed for business.
func (*Shop) Close ¶
func (s *Shop) Close()
Close prevents any new customers from entering the shop and waits for the barber to finish all existing customers.
func (*Shop) EnterCustomer ¶
EnterCustomer is called to create a customer to be serviced. If the shop is closed the function returns an error. If the shop is open, a goroutine is created to handle the customers concurrently.