MCPcopy Create free account
hub / github.com/3rdparty/libprocess / acquire

Method acquire

include/process/limiter.hpp:89–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87 }
88
89 Future<Nothing> acquire()
90 {
91 if (!promises.empty()) {
92 // Need to wait for others to get permits first.
93 Promise<Nothing>* promise = new Promise<Nothing>();
94 promises.push_back(promise);
95 return promise->future()
96 .onDiscard(defer(self(), &Self::discard, promise->future()));
97 }
98
99 if (timeout.remaining() > Seconds(0)) {
100 // Need to wait a bit longer, but first one in the queue.
101 Promise<Nothing>* promise = new Promise<Nothing>();
102 promises.push_back(promise);
103 delay(timeout.remaining(), self(), &Self::_acquire);
104 return promise->future()
105 .onDiscard(defer(self(), &Self::discard, promise->future()));
106 }
107
108 // No need to wait!
109 timeout = Seconds(1) / permitsPerSecond;
110 return Nothing();
111 }
112
113private:
114 // Not copyable, not assignable.

Callers

nothing calls this directly

Calls 5

deferFunction · 0.85
futureMethod · 0.80
delayFunction · 0.70
emptyMethod · 0.45
remainingMethod · 0.45

Tested by

no test coverage detected