* @param nanos timeout in nanosecs, used only if timed is true
* @return matched item, or e if unmatched on interrupt or timeout
*/
private Message awaitMatch(Node s, Node pred, Message e, boolean timed, long nanos) throws SuspendExecution {
long lastTime = timed ? System.nanoTime() : 0L;
Strand w = Strand.currentStrand();
int spins = (w instanceof Fiber ? 0 : -1); // no spins in fiber; otherwise, initialized after first item and cancel checks
ThreadLocalRandom randomYields = null; // bound if needed
if(spins == 0)
s.waiter = w;
for (;;) {
Object item = s.item;
if (item == CHANNEL_CLOSED)
setReceiveClosed();
if (item != e) { // matched
// assert item != s;
s.forgetContents(); // avoid garbage
return this.<Message>cast(item);
}
if ((w.isInterrupted() || (timed && nanos <= 0))
&& s.casItem(e, s)) { // cancel
unsplice(pred, s);
return e;
}