trySeizeZones

open suspend fun trySeizeZones(space: GuidedPathSpace, zones: List<Zone>, queue: HoldQueue, requestPriority: Int = QUEUE_PRIORITY, suspensionName: String? = null): ZoneAllocation?(source)

Takes a set of zones, and answers null when some zone of it is already promised.

seizeZones with the one refusable condition turned into an answer, and the form a model wants whenever a closure lands where it lands rather than where it was told to. A zone carries one promise at a time, and by default a second asker is refused rather than queued behind the first -- ZoneOverlap.QUEUE is the opt-in for waiting instead. So a model with spills at random locations has to say what an overlap means. This is how it says it, in one call that cannot be got wrong.

inner class Spill : Entity() {
val cleanup = process {
val extent = aisle.zones.take(myExtent.value.toInt())
// A spill landing where one is already being dealt with is part of that spill.
if (trySeizeZones(system, extent, spillQ) == null) {
myAbsorbed.increment()
return@process
}
delay(myCleanupTime)
releaseZones(system)
}
}

Null is answered without suspending. A zone another holder already holds is not an overlap and does not answer null: that is the ordinary case, and this waits for the hold to end exactly as seizeZones would.

Return

the hold, or null when some zone of the set is already promised to another holder

Parameters

space

the guide path whose space is wanted

zones

the zones to take, all on that guide path, distinct, at least one

queue

where to wait while they drain

requestPriority

orders this entity against others queued at the same instant

suspensionName

names this suspension point when a process has several