You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my usages of sempahore, I'm doing something like:
constmaxWeight=...sema:=semaphore.NewWeighted(maxWeight)
...for... {
size:=object.Size()
ifsize>maxWeight {
// Object is too large to fit in memory, switch to a streaming mode.object.StreamingMode(true)
size=maxWeight// use the maximum weight to have exclusive lock over semaphore
}
sema.Acquire(size)
gofunc() {
defersema.Release(size)
...
}
}
You will notice that I'm passing around both sema and maxWeight. However, this is a somewhat unnecessary since the unexported sema.size field is exactly the information I need.
I propose adding a Capacity method:
// Capacity returns the maximum combined weight this semaphore is constructed with.func (s*Weighted) Capacity() int64 {
returns.size
}
Alternative names: Weight, MaxWeight, MaxSize. We should choose a name that would not prevent the possible future addition of a something like Length where we return the value of s.cur. The names of Length of Capacity would match the names of len(c) and cap(c) when a channel is used a semaphore.
In my usages of
sempahore
, I'm doing something like:You will notice that I'm passing around both
sema
andmaxWeight
. However, this is a somewhat unnecessary since the unexportedsema.size
field is exactly the information I need.I propose adding a
Capacity
method:Alternative names:
Weight
,MaxWeight
,MaxSize
. We should choose a name that would not prevent the possible future addition of a something likeLength
where we return the value ofs.cur
. The names ofLength
ofCapacity
would match the names oflen(c)
andcap(c)
when a channel is used a semaphore.\cc @jba
The text was updated successfully, but these errors were encountered: