Blocks until messages are available
@param num_spins the number of times we should spin before acquiring a lock
@param wait_strategy the strategy used to spin. The first parameter is the iteration count and the second
parameter is the max number of spins
342363
public int waitForMessages(int num_spins, final BiConsumer<Integer,Integer> wait_strategy) throws InterruptedException {
        // try spinning first (experimental)
        for(int i=0; i < num_spins && count == 0; i++) {
            if(wait_strategy != null)
                wait_strategy.accept(i, num_spins);
            else
                Thread.yield();
        }
        if(count == 0)
            _waitForMessages();
        return count; // whatever is the last count; could have been updated since lock release
    }
1081655
private synchronized void waitNextLoop(long ms) {
        try {
            wait(ms);
        } catch (InterruptedException e) {
            System.err.println(e);
        }
    }
145140
public void await(int ID) throws InterruptedException
    {
        if(parties == 1)//what are you doing?!
            return;
        final boolean startCondition = competitionCondition;
        int competingFor = (locks.length*2-1-ID)/2;
        
        while (competingFor >= 0)
        {
            final Lock node = locks[competingFor];
            if (node.tryLock())//we lose, must wait
            {
                synchronized (node)//ignore warning, its correct. We are using the lock both for competition AND to do an internal wait
                {
                    while(competitionCondition == startCondition)
                        node.wait();
                }
                node.unlock();
                
                wakeUpTarget(competingFor*2+1);
                wakeUpTarget(competingFor*2+2);
                return;
            }
            else //we win, comete for another round!
            {
                if(competingFor == 0)
                    break;//we have won the last round!
                competingFor = (competingFor-1)/2;
            }
        }
        
        //We won! Inform the losers
        competitionCondition = !competitionCondition;
        wakeUpTarget(0);//biggest loser
    }
1257328
void invokeAndWait(final Runnable r) {
        final CountDownLatch latch = new CountDownLatch(1);
        queue.postRunnable(() -> {
            try {
                r.run();
            } finally {
                latch.countDown();
            }
        });
        try {
            latch.await();
        } catch (InterruptedException e) { }
    }
713745
@Override
    protected void beforeWaitForSynchronization(final T message) throws CouldNotPerformException {
        transactionIdField = ProtoBufFieldProcessor.getFieldDescriptor(message, TransactionIdProvider.TRANSACTION_ID_FIELD_NAME);
        if (transactionIdField == null) {
            throw new NotAvailableException("transaction id field for message[" + message.getClass().getSimpleName() + "]");
        }

        if (transactionIdField.getType() != Type.UINT64) {
            throw new CouldNotPerformException("Transaction id field of message[" + message.getClass().getSimpleName() + "] has an unexpected type[" + transactionIdField.getType().name() + "]");
        }
    }
1229367
@FFDCIgnore(InterruptedException.class)
    private boolean waitForIndex(int index) {
        final String methodName = "waitForIndex(): ";
        while (!!!tryToFetchElement(index)) {
            try {
                if (stateLock.hasTimedOut()) {
                    markTimedOut();
                    if (tc.isDebugEnabled())
                        Tr.debug(tc, methodName + "TIMED OUT!");
                    return false;
                }
                if (tc.isDebugEnabled())
                    Tr.debug(tc, methodName + "waiting ...");
                boolean result = stateLock.waitForEvent();
                if (tc.isDebugEnabled())
                    Tr.debug(tc, methodName + "waitForEvent result is [" + result + "] will Loop again to check timeout");
            } catch (InterruptedException ignored) {
                // NO FFDC
                if (tc.isDebugEnabled())
                    Tr.debug(tc, methodName + "interrupted");
            }
        }
        return true;
    }
760642
def spin
      synchronize do
        return if @done
        emit(:spin)

        if @hide_cursor && !spinning?
          write(TTY::Cursor.hide)
        end

        data = message.gsub(MATCHER, @frames[@current])
        data = replace_tokens(data)
        write(data, true)
        @current = (@current + 1) % @length
        @state = :spinning
        data
      end
    end
1318894
public void waitForLock(T jedis){
        while(!lock(jedis)){
            try {
                logger.debug("Waiting for Redis lock.");
                Thread.sleep(randomInt(75, 125));
            } catch (InterruptedException e) {
                logger.error("Interrupted while waiting for lock.", e);
            }
        }
    }
744239
def wait(self, delay):
        
        for _ in range(0, delay):
            self._add_step((self._rec_x, self._rec_y))
340237
def wait_message(self):
        
        if self._state != states['open']:
            return False
        if len(self._read_queue) > 0:
            return True

        assert self._read_waiter is None or self._read_waiter.cancelled(), \
            "You may only use one wait_message() per connection."

        self._read_waiter = asyncio.Future(loop=self._loop)
        yield from self._read_waiter
        return self.wait_message()
313863
def _wait(self, duration, steps, commands):
        
        wait = ((duration - self.wait * self.reps * commands) / steps) - \
               (self.wait * self.reps * self._bridge.active)
        return max(0, wait)
1295659
public static boolean tryLock(String key, int wait) throws InterruptedException {
        return getLock(key).tryLock(wait, TimeUnit.MILLISECONDS);
    }
1338684
public static <E> BlockingQueue<E> getWaitingLimitedBlockingQueue(
            long waitingMillis, int maxQueue) {
        return new LinkedBlockingQueue<E>(maxQueue) {
            @Override
            public boolean offer(E e) {
                if (size() >= maxQueue) {
                    sleep(waitingMillis);
                    log.warn("Wait For {} ms And Blocking !!! - maxQueue = {}",
                            waitingMillis, maxQueue);
                }
                return putInsteadOfOffer(this, e);
            }
        };
    }
808553
public void waitOnChains(long quiesceTimeout) {

        ChannelFramework cf = ChannelFrameworkFactory.getChannelFramework();
        int elapsedTime = 0;
        if (waitingChainNames.size() > 0 && elapsedTime < quiesceTimeout) {

            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(this, tc, "Waiting on " + waitingChainNames.size() + " chain(s) to stop");
            }

            Iterator<String> iter = waitingChainNames.iterator();
            while (iter.hasNext()) {
                if (!cf.isChainRunning(iter.next()))
                    iter.remove();
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                // ignore
            }
            elapsedTime += 1000;

        }

    }
835936
def _wait_for_lock(self, lock_file):
        
        sleeptime = .5
        first_message_flag = False
        dot_count = 0
        recover_file = self._recoverfile_from_lockfile(lock_file)
        while os.path.isfile(lock_file):
            if first_message_flag is False:
                self.timestamp("Waiting for file lock: " + lock_file)
                self._set_status_flag(WAIT_FLAG)
                first_message_flag = True
            else:
                sys.stdout.write(".")
                dot_count = dot_count + 1
                if dot_count % 60 == 0:
                    print("")  # linefeed
            # prevents the issue of pypier waiting for the lock file to be gone infinitely
            # in case the recovery flag is sticked by other pipeline when it's interrupted
            if os.path.isfile(recover_file):
                sys.stdout.write(" Dynamic recovery flag found")
                break
            time.sleep(sleeptime)
            sleeptime = min(sleeptime + 2.5, 60)

        if first_message_flag:
            self.timestamp("File unlocked.")
            self._set_status_flag(RUN_FLAG)
838917
async def wait_read(self, message=None, *, timeout=None):
        
        start_time = time.time()
        future = self._client.loop.create_future()
        target_id = self._get_message_id(message)

        if self._last_read is None:
            self._last_read = target_id - 1

        if self._last_read >= target_id:
            return

        self._pending_reads[target_id] = future
        return await self._get_result(future, start_time, timeout)
565893
def incrementing_sleep(self, previous_attempt_number, delay_since_first_attempt_ms):
        
        result = self._wait_incrementing_start + (self._wait_incrementing_increment * (previous_attempt_number - 1))
        if result < 0:
            result = 0
        return result