This is a method that will be called when the time remaining ends.
        The current state can be: roasting, cooling, idle, sleeping, connecting,
        or unkown.
543831
def next_state(self):
        """"""
        self.active_recipe_item += 1
        if self.active_recipe_item >= len(self.recipe):
            # we're done!
            return
        # show state step on screen
        print("--------------------------------------------")
        print("Setting next process step: %d" % self.active_recipe_item)
        print("time:%d, target: %ddegF, fan: %d, state: %s" %
              (self.recipe[self.active_recipe_item]['time_remaining'],
               self.recipe[self.active_recipe_item]['target_temp'],
               self.recipe[self.active_recipe_item]['fan_speed'],
               self.recipe[self.active_recipe_item]['state']
               ))
        print("--------------------------------------------")
        # set values for next state
        self.roaster.time_remaining = (
            self.recipe[self.active_recipe_item]['time_remaining'])
        self.roaster.target_temp = (
            self.recipe[self.active_recipe_item]['target_temp'])
        self.roaster.fan_speed = (
            self.recipe[self.active_recipe_item]['fan_speed'])
        # set state
        if(self.recipe[self.active_recipe_item]['state'] == 'roasting'):
            self.roaster.roast()
        elif(self.recipe[self.active_recipe_item]['state'] == 'cooling'):
            self.roaster.cool()
        elif(self.recipe[self.active_recipe_item]['state'] == 'idle'):
            self.roaster.idle()
        elif(self.recipe[self.active_recipe_item]['state'] == 'cooling'):
            self.roaster.sleep()
649880
public void waitEnd(final long... timeout) {

        long start = System.currentTimeMillis();
        if (timeout.length == 1) {
            start += timeout[0];
        } else {
            start += DEFAULT_TIME_OUT;
        }

        while (!this.hasRun.get()) {
            try {
                Thread.sleep(SLEEP_TIME);
            } catch (final InterruptedException e) {
                break;
            }
            if (System.currentTimeMillis() > start) {
                break; // Break the loop after 1s to avoid freezing the thread
            }
        }

    }
482225
def Wait(self):
    """"""
    time.sleep(self.sleep_time - int(self.sleep_time))

    # Split a long sleep interval into 1 second intervals so we can heartbeat.
    for _ in range(int(self.sleep_time)):
      time.sleep(1)

    # Back off slowly at first and fast if no answer.
    self.sleep_time = min(self.poll_max,
                          max(self.poll_min, self.sleep_time) * self.poll_slew)
733588
def sleep(self, seconds=0.05, dt=0.01):
        
        t0 = _t.time()
        while _t.time()-t0 < seconds:
            
            # Pause a bit to avoid heavy CPU
            _t.sleep(dt)
            
            # process events
            self.process_events()
118377
function() {
      var t = this,
          now = Date.now();

      // This kicks off the send
      t.lastSendTime = now;
      t.set({
        bundle: t.queue,
        sequence: t.get('sequence') + 1
      });

      // Reset
      t.queue = [];
      if (t.timer) {
        clearTimeout(t.timer);
        t.timer = null;
      }
    }
1123409
def _wait(self):
		""
		elapsed = time.time() - self.last_called
		must_wait = 1 / self.max_rate - elapsed
		time.sleep(max(0, must_wait))
		self.last_called = time.time()
316042
function finish(cb) {
      clearTimeout(timer);
      timer = null;
      return subscriber.unsubscribe(
        'message/' + id + '/' + getIndex, cb);
    }
847143
public void shutdownAndWaitUntilDone()
    {
        shutdown();
        while(true)
        {
            synchronized (endSignal)
            {
                try
                {
                    if ((combinedState.get() & 0x7FFFFFFFFFFFFFFFL) == 0) break;
                    endSignal.wait(100);
                }
                catch (InterruptedException e)
                {
                    // ignore
                }
            }
        }
    }
1197958
def finish(self):
        ""
        log.debug("Session disconnected.")
        try:
            self.sock.shutdown(socket.SHUT_RDWR)
        except: pass
        self.session_end()
1067281
private void scheduleKeepAlive() {
    if (keepAlive != null)
      keepAlive.cancel();
    keepAlive = context.schedule(interval, () -> {
      keepAlive = null;
      if (state.getState().active()) {
        keepAlive();
      }
    });
  }
851062
def finish(end_time = ::Instana::Util.now_in_ms)
      if ::Instana.tracer.current_span.id != id
        ::Instana.logger.debug "Closing a span that isn't active. This will result in a broken trace: #{self.inspect}"
      end

      if is_root?
        # This is the root span for the trace.  Call log_end to close
        # out and queue the trace
        ::Instana.tracer.log_end(name, {}, end_time)
      else
        ::Instana.tracer.current_trace.end_span({}, end_time)
      end
      self
    end
1332298
def ended(self):
        """"""
        self._end_time = time.time()

        if setting(key='memory_profile', expected_type=bool):
            self._end_memory = get_free_memory()
786135
def end_segment(self, end_time=None):
        
        self.context.end_segment(end_time)
        segment = self.current_segment()
        if segment and segment.ready_to_send():
            self._send_segment()
396510
def now_heating(self):
        """"""
        try:
            if self.side == 'left':
                heat = self.device.device_data['leftNowHeating']
            elif self.side == 'right':
                heat = self.device.device_data['rightNowHeating']
            return heat
        except TypeError:
            return None
1146432
def idle_task(self):
        ''''''
        now = time.time()
        if now - self.last_chan_check >= 1:
            self.last_chan_check = now
            self.update_channels()
1130140
def idle_task(self):
        ''''''
        now = time.time()

        if now-self.last_sent > self.system_time_settings.interval:
            self.last_sent = now
            time_us = time.time() * 1000000
            if self.system_time_settings.verbose:
                print("ST: Sending system time: (%u/%u)" %
                      (time_us, self.uptime(),))
            self.master.mav.system_time_send(time_us,
                                             self.uptime())

        if (now-self.last_sent_timesync >
            self.system_time_settings.interval_timesync):
            self.last_sent_timesync = now
            time_ns = time.time() * 1000000000
            time_ns += 1234
            if self.system_time_settings.verbose:
                print("ST: Sending timesync request")
            self.master.mav.timesync_send(0, time_ns)
            self.last_sent_ts1 = time_ns
30924
def reset_state(self):
        
        self.active_message = None
        self.measurement = None
        if self.is_waiting_to_shutdown:
            self.shutdown_connections()
        elif self.is_processing:
            self.set_state(self.STATE_IDLE)
        elif self.is_idle or self.is_connecting or self.is_shutting_down:
            pass
        else:
            LOGGER.critical('Unexepected state: %s', self.state_description)
        LOGGER.debug('State reset to %s (%s in pending)',
                     self.state_description, len(self.pending))