Plug a device to draw power from the `Socket`
(device PowerDrawer)
| 26 | |
| 27 | // Plug a device to draw power from the `Socket` |
| 28 | func (s *Socket) Plug(device PowerDrawer) error { |
| 29 | n := rand.Intn(50) + 1 |
| 30 | |
| 31 | if s.power-n < 0 { |
| 32 | return fmt.Errorf("socket is out of power for %dkW", n) |
| 33 | } |
| 34 | |
| 35 | s.power -= n |
| 36 | device.Draw(n) |
| 37 | |
| 38 | return nil |
| 39 | } |