// poller polls the rd_kafka_t handle for events until signalled for termination
550864
func poller(p *Producer, termChan chan bool) {
out:
	for true {
		select {
		case _ = <-termChan:
			break out

		default:
			_, term := p.handle.eventPoll(p.events, 100, 1000, termChan)
			if term {
				break out
			}
			break
		}
	}

	p.handle.terminatedChan <- "poller"

}
74517
func (s *Server) poll() {
	for !isTagged(s.url) {
		pollSleep(s.period)
	}
	s.mu.Lock()
	s.yes = true
	s.mu.Unlock()
	pollDone()
}
16486
func BlockingPoll(fds *PollEvent, nfds int, timeout int64) (int, syscall.Errno) {
	n, _, e := syscall.Syscall(syscall.SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout))
	return int(n), e
}
1245898
func pollEvents() {
	defer context.wg.Done()
	for {
		errCode := C.memif_poll_event(C.int(-1))
		err := getMemifError(int(errCode))
		if err == ErrPollCanceled {
			return
		}
	}
}
1162328
func (task *TCPListenerTask) StopErr(err error) {
	task.LoopTask.StopErrFunc(func() error {
		task.stop()
		return err
	})
}
75346
func (p *asyncProducer) dispatcher() {
	handlers := make(map[string]chan<- *ProducerMessage)
	shuttingDown := false

	for msg := range p.input {
		if msg == nil {
			Logger.Println("Something tried to send a nil message, it was ignored.")
			continue
		}

		if msg.flags&shutdown != 0 {
			shuttingDown = true
			p.inFlight.Done()
			continue
		} else if msg.retries == 0 {
			if shuttingDown {
				// we can't just call returnError here because that decrements the wait group,
				// which hasn't been incremented yet for this message, and shouldn't be
				pErr := &ProducerError{Msg: msg, Err: ErrShuttingDown}
				if p.conf.Producer.Return.Errors {
					p.errors <- pErr
				} else {
					Logger.Println(pErr)
				}
				continue
			}
			p.inFlight.Add(1)
		}

		version := 1
		if p.conf.Version.IsAtLeast(V0_11_0_0) {
			version = 2
		} else if msg.Headers != nil {
			p.returnError(msg, ConfigurationError("Producing headers requires Kafka at least v0.11"))
			continue
		}
		if msg.byteSize(version) > p.conf.Producer.MaxMessageBytes {
			p.returnError(msg, ErrMessageSizeTooLarge)
			continue
		}

		handler := handlers[msg.Topic]
		if handler == nil {
			handler = p.newTopicProducer(msg.Topic)
			handlers[msg.Topic] = handler
		}

		handler <- msg
	}

	for _, handler := range handlers {
		close(handler)
	}
}
429197
func (s *Stream) Poll() (bool, error) {
	poll := C.Pm_Poll(unsafe.Pointer(s.pmStream))
	if poll < 0 {
		return false, convertToError(C.PmError(poll))
	}
	return poll > 0, nil
}
1293922
func (client *Client) PollJob(job Job) (Warnings, error) {
	originalJobGUID := job.GUID

	var (
		err         error
		warnings    Warnings
		allWarnings Warnings
	)

	startTime := time.Now()
	for time.Now().Sub(startTime) < client.jobPollingTimeout {
		job, warnings, err = client.GetJob(job.GUID)
		allWarnings = append(allWarnings, Warnings(warnings)...)
		if err != nil {
			return allWarnings, err
		}

		if job.Failed() {
			return allWarnings, ccerror.V2JobFailedError{
				JobGUID: originalJobGUID,
				Message: job.ErrorDetails.Description,
			}
		}

		if job.Finished() {
			return allWarnings, nil
		}

		time.Sleep(client.jobPollingInterval)
	}

	return allWarnings, ccerror.JobTimeoutError{
		JobGUID: originalJobGUID,
		Timeout: client.jobPollingTimeout,
	}
}
693989
func (d *Document) Poll(ctx context.Context, pause time.Duration) APIResponse {
	// store upload duration. Will be overwritten otherwise
	uploadDuration := d.Timing.Upload

	start := time.Now()
	defer func() { d.Timing.Processing = time.Since(start) }()

	type CombinedResponse struct {
		doc  *Document
		resp APIResponse
	}

	docProgress := make(chan CombinedResponse, 1)

	go func(ctx context.Context) {
		for {
			select {
			case <-ctx.Done():
				return
			default:
				doc, getResponse := d.client.Get(ctx, d.Links.Document, d.Owner)
				docResponse := CombinedResponse{doc, getResponse}

				// we need to keep polling until we hit an error or finish processing
				if getResponse.Error != nil || (doc.Progress == "COMPLETED" || doc.Progress == "ERROR") {
					docProgress <- docResponse
					return
				}

				// be a (potentially) good neighbour
				time.Sleep(pause)
			}
		}
	}(ctx)

	select {
	case answer := <-docProgress:
		if answer.doc == nil || answer.resp.Error != nil {
			return answer.resp
		}

		// replace ourself with the polled document
		*d = *answer.doc

		// restore upload duration
		d.Timing.Upload = uploadDuration

		return apiResponse("polling completed", d.ID, answer.resp.HttpResponse, nil)
	case <-ctx.Done():
		return apiResponse("polling aborted", d.ID, nil, ctx.Err())
	}
}
538984
func PollEvent() Event {
	// Constant governing macOS specific behavior. See https://github.com/nsf/termbox-go/issues/132
	// This is an arbitrary delay which hopefully will be enough time for any lagging
	// partial escape sequences to come through.
	const esc_wait_delay = 100 * time.Millisecond

	var event Event
	var esc_wait_timer *time.Timer
	var esc_timeout <-chan time.Time

	// try to extract event from input buffer, return on success
	event.Type = EventKey
	status := extract_event(inbuf, &event, true)
	if event.N != 0 {
		copy(inbuf, inbuf[event.N:])
		inbuf = inbuf[:len(inbuf)-event.N]
	}
	if status == event_extracted {
		return event
	} else if status == esc_wait {
		esc_wait_timer = time.NewTimer(esc_wait_delay)
		esc_timeout = esc_wait_timer.C
	}

	for {
		select {
		case ev := <-input_comm:
			if esc_wait_timer != nil {
				if !esc_wait_timer.Stop() {
					<-esc_wait_timer.C
				}
				esc_wait_timer = nil
			}

			if ev.err != nil {
				return Event{Type: EventError, Err: ev.err}
			}

			inbuf = append(inbuf, ev.data...)
			input_comm <- ev
			status := extract_event(inbuf, &event, true)
			if event.N != 0 {
				copy(inbuf, inbuf[event.N:])
				inbuf = inbuf[:len(inbuf)-event.N]
			}
			if status == event_extracted {
				return event
			} else if status == esc_wait {
				esc_wait_timer = time.NewTimer(esc_wait_delay)
				esc_timeout = esc_wait_timer.C
			}
		case <-esc_timeout:
			esc_wait_timer = nil

			status := extract_event(inbuf, &event, false)
			if event.N != 0 {
				copy(inbuf, inbuf[event.N:])
				inbuf = inbuf[:len(inbuf)-event.N]
			}
			if status == event_extracted {
				return event
			}
		case <-interrupt_comm:
			event.Type = EventInterrupt
			return event

		case <-sigwinch:
			event.Type = EventResize
			event.Width, event.Height = get_term_size(out.Fd())
			return event
		}
	}
}
1303680
func (m *Metrics) PollGoMetrics() {
	m.GoMetricsRegistry.Each(func(name string, value interface{}) {
		recordMeter := func(prefix, label string, gauge metrics.Gauge) bool {
			if !strings.HasPrefix(name, prefix) {
				return false
			}

			meter, ok := value.(gometrics.Meter)
			if !ok {
				logger.Panicf("Expected metric with name %s to be of type Meter but was of type %T", name, value)
			}

			labelValue := name[len(prefix):]
			gauge.With(label, labelValue).Set(meter.Snapshot().Rate1())

			return true
		}

		recordHistogram := func(prefix, label string, gauge metrics.Gauge) bool {
			if !strings.HasPrefix(name, prefix) {
				return false
			}

			histogram, ok := value.(gometrics.Histogram)
			if !ok {
				logger.Panicf("Expected metric with name %s to be of type Histogram but was of type %T", name, value)
			}

			labelValue := name[len(prefix):]
			gauge.With(label, labelValue).Set(histogram.Snapshot().Mean())

			return true
		}

		switch {
		case recordMeter(IncomingByteRateName, "broker_id", m.IncomingByteRate):
		case recordMeter(OutgoingByteRateName, "broker_id", m.OutgoingByteRate):
		case recordMeter(RequestRateName, "broker_id", m.RequestRate):
		case recordHistogram(RequestSizeName, "broker_id", m.RequestSize):
		case recordHistogram(RequestLatencyName, "broker_id", m.RequestLatency):
		case recordMeter(ResponseRateName, "broker_id", m.ResponseRate):
		case recordHistogram(ResponseSizeName, "broker_id", m.ResponseSize):
		case recordHistogram(BatchSizeName, "topic", m.BatchSize):
		case recordMeter(RecordSendRateName, "topic", m.RecordSendRate):
		case recordHistogram(RecordsPerRequestName, "topic", m.RecordsPerRequest):
		case recordHistogram(CompressionRatioName, "topic", m.CompressionRatio):
		default:
			// Ignore unknown metrics
		}
	})
}
914950
func (q *LinkedBlockingDeque) PollLast() interface{} {
	q.lock.Lock()
	result := q.unlinkLast()
	q.lock.Unlock()
	return result
}
118125
func (k *KafkaRequesterFactory) GetRequester(num uint64) bench.Requester {
	return &kafkaRequester{
		urls:        k.URLs,
		payloadSize: k.PayloadSize,
		topic:       k.Topic + "-" + strconv.FormatUint(num, 10),
	}
}
443617
func ServicePoll(config *poll.Settings) {
	// Override the default pollSettings for `service` resource here ...
	config.Timeout = 30 * time.Second
	config.Delay = 100 * time.Millisecond
	if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" {
		config.Timeout = 90 * time.Second
	}
}
281504
func (t *File) pollForRotations(d time.Duration) {
	previousFile, err := t.file.Stat()
	if err != nil {
		t.errc <- err
	}

	for !t.closed {
		currentFile, err := os.Stat(t.filename)
		switch err {
		case nil:
			switch os.SameFile(currentFile, previousFile) {
			case true:
				if t.checkForTruncate() {
					if err := t.reopenFile(); err != nil {
						t.errc <- err
					}
				}
			case false:
				previousFile = currentFile
				if err := t.reopenFile(); err != nil {
					t.errc <- err
				}
			}
		default:
			// Filename doens't seem to be there (or something else weird), wait for it to re-appear
		}

		time.Sleep(d)
	}
}
892991
func (poller *fdPoller) wake() error {
	buf := make([]byte, 1)
	n, errno := unix.Write(poller.pipe[1], buf)
	if n == -1 {
		if errno == unix.EAGAIN {
			// Buffer is full, poller will wake.
			return nil
		}
		return errno
	}
	return nil
}
883299
func (vote *ProjectPostCommentVote) Sender() (user *User) {
	user, _ = NewUser(vote.From)
	return
}