all repos — honk @ 61efaeb33b39829907235c340792765a773005cf

my fork of honk

put a limit on how many deliveries we actually send it in parallel
Ted Unangst tedu@tedunangst.com
Tue, 16 Apr 2019 20:34:27 -0400
commit

61efaeb33b39829907235c340792765a773005cf

parent

f3447859af66e3fc0b28a7a754316cfe385910e2

1 files changed, 25 insertions(+), 0 deletions(-)

jump to
M deliverator.godeliverator.go

@@ -18,6 +18,7 @@

import ( "log" notrand "math/rand" + "sync" "time" )

@@ -54,7 +55,31 @@ default:

} } +var trucksout = 0 +var maxtrucksout = 10 +var garagelock sync.Mutex +var garagebell = sync.NewCond(&garagelock) + +func truckgoesout() { + garagelock.Lock() + for trucksout >= maxtrucksout { + garagebell.Wait() + } + trucksout++ + garagelock.Unlock() +} + +func truckcomesin() { + garagelock.Lock() + trucksout-- + garagebell.Broadcast() + garagelock.Unlock() +} + func deliverate(goarounds int, username string, rcpt string, msg []byte) { + truckgoesout() + defer truckcomesin() + keyname, key := ziggy(username) var inbox string // already did the box indirection