MCPcopy
hub / github.com/inancgumus/learngo / Plug

Method Plug

interfaces/04-interfaces/power/socket.go:28–39  ·  view source on GitHub ↗

Plug a device to draw power from the `Socket`

(device PowerDrawer)

Source from the content-addressed store, hash-verified

26
27// Plug a device to draw power from the `Socket`
28func (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}

Callers 1

mainFunction · 0.95

Calls 1

DrawMethod · 0.65

Tested by

no test coverage detected