// Start the polling of the events on the URL defined in the client
// Will send the events in the EventsChan of the client
2814
func (c *Client) Start() {
	u := c.url
	if c.LoggingEnabled {
		log.Println("Now observing changes on", u.String())
	}

	atomic.AddUint64(&(c.runID), 1)
	currentRunID := atomic.LoadUint64(&(c.runID))

	go func(runID uint64, u *url.URL) {
		since := time.Now().Unix() * 1000
		for {
			pr, err := c.fetchEvents(since)

			if err != nil {
				if c.LoggingEnabled {
					log.Println(err)
					log.Printf("Reattempting to connect to %s in %d seconds", u.String(), c.Reattempt)
				}
				time.Sleep(c.Reattempt)
				continue
			}

			// We check that its still the same runID as when this goroutine was started
			clientRunID := atomic.LoadUint64(&(c.runID))
			if clientRunID != runID {
				if c.LoggingEnabled {
					log.Printf("Client on URL %s has been stopped, not sending events", u.String())
				}
				return
			}

			if len(pr.Events) > 0 {
				if c.LoggingEnabled {
					log.Println("Got", len(pr.Events), "event(s) from URL", u.String())
				}
				for _, event := range pr.Events {
					since = event.Timestamp
					c.EventsChan <- event
				}
			} else {
				// Only push timestamp forward if its greater than the last we checked
				if pr.Timestamp > since {
					since = pr.Timestamp
				}
			}
		}
	}(currentRunID, u)
}
493904
func (c *Client) SendEvent(event Event, opts ...interface{}) (res StatusMessageRes, err error) {
	return c.SendEvents([]Event{event}, opts...)
}
533060
func (es *EventStream) Start() {
	if es.Events == nil {
		es.Events = make(chan []Event)
	}

	// register eventstream in the local registry for later lookup
	// in C callback
	cbInfo := registry.Add(es)
	es.registryID = cbInfo
	es.uuid = GetDeviceUUID(es.Device)
	es.start(es.Paths, cbInfo)
}
450234
func Start(w http.ResponseWriter, r *http.Request) *Session {
	return Default.Start(w, r)
}
1028482
func (il *ILertNotifier) sendEvent(event iLertEvent) error {
	body, err := json.Marshal(event)
	if err != nil {
		return err
	}

	res, err := http.Post(apiEndpoint, "application/json", bytes.NewBuffer(body))
	if err != nil {
		return err
	}

	defer res.Body.Close()

	if res.StatusCode != 200 {
		body, _ := ioutil.ReadAll(res.Body)
		return errors.New(fmt.Sprintf("Unexpected HTTP status code: %d (%s)", res.StatusCode, string(body)))
	}

	return nil
}
966644
func sendEvents(evtChan chan *dt.ScheduledEvent, interval time.Duration) {
	t := time.NewTicker(time.Minute)
	select {
	case now := <-t.C:
		sendEventsTick(evtChan, now)
		sendEvents(evtChan, interval)
	}
}
838926
func (_m *APIClient) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) {
	ret := _m.Called(ctx, options)

	var r0 <-chan events.Message
	if rf, ok := ret.Get(0).(func(context.Context, types.EventsOptions) <-chan events.Message); ok {
		r0 = rf(ctx, options)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(<-chan events.Message)
		}
	}

	var r1 <-chan error
	if rf, ok := ret.Get(1).(func(context.Context, types.EventsOptions) <-chan error); ok {
		r1 = rf(ctx, options)
	} else {
		if ret.Get(1) != nil {
			r1 = ret.Get(1).(<-chan error)
		}
	}

	return r0, r1
}
274884
func (c *Client) StartServer() {
	mux := http.NewServeMux()
	mux.Handle("/", c)
	log.Printf("Listening on http://%v...\n", c.BindAddress)
	if err := http.ListenAndServe(c.BindAddress, mux); err != nil {
		log.Fatal(err)
	}
}
1338611
func (c *StatsdClient) SendEvent(e event.Event) error {
	if c.conn == nil {
		return errNotConnected
	}
	for _, stat := range e.Stats() {
		//fmt.Printf("SENDING EVENT %s%s\n", c.prefix, strings.Replace(stat, "%HOST%", Hostname, 1))
		_, err := fmt.Fprintf(c.conn, "%s%s", c.prefix, strings.Replace(stat, "%HOST%", Hostname, 1))
		if nil != err {
			return err
		}
	}
	return nil
}
429599
func (s *Service) Start() error {
	err := s.startChannel()
	if err != nil {
		return err
	}

	s.wg.Add(1)
	go func() {
		defer s.wg.Done()

		// Same polling interval and backoff logic as vmtoolsd.
		// Required in our case at startup at least, otherwise it is possible
		// we miss the 1 Capabilities_Register call for example.

		// Note we Send(response) even when nil, to let the VMX know we are here
		var response []byte

		for {
			select {
			case <-s.stop:
				s.stopChannel()
				return
			case <-time.After(time.Millisecond * 10 * s.delay):
				if err = s.checkReset(); err != nil {
					continue
				}

				err = s.in.Send(response)
				response = nil
				if err != nil {
					s.delay = resetDelay
					s.rpcError = true
					continue
				}

				request, _ := s.in.Receive()

				if len(request) > 0 {
					response = s.Dispatch(request)

					s.delay = 0
				} else {
					s.backoff()
				}
			}
		}
	}()

	return nil
}
1099567
func SendEvents(c Client, e *[]Event) (*proto.Msg, error) {
	buff := make(
		[]*proto.Event, len(*e),
	)

	for i, elem := range *e {
		epb, err := EventToProtocolBuffer(
			&elem,
		)

		if err != nil {
			return nil, err
		}

		buff[i] = epb
	}

	message := new(proto.Msg)
	message.Events = buff

	return c.Send(message)
}
39523
func (bot *TgBot) Start() {
	if bot.ID == 0 {
		fmt.Println("No ID, maybe the token is bad.")
		return
	}

	if bot.MainListener == nil {
		fmt.Println("No listener!")
		return
	}

	removedhook := false

	for {
		updatesList, err := bot.GetUpdates()
		if err != nil {
			fmt.Println(err)
			if !removedhook {
				fmt.Println("Removing webhook...")
				bot.SetWebhook("")
				removedhook = true
			}
			continue
		}
		bot.ProcessMessages(updatesList)
	}
}
543280
func (self *FSock) SendEvent(eventSubclass string, eventParams map[string]string) (string, error) {
	return self.SendEventWithBody(eventSubclass, eventParams, "")
}
178998
func (mod *GitHubBee) Run(eventChan chan bees.Event) {
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: mod.accessToken},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)

	mod.eventChan = eventChan
	mod.client = github.NewClient(tc)

	since := time.Now() // .Add(-time.Duration(24 * time.Hour))
	timeout := time.Duration(time.Second * 10)
	for {
		select {
		case <-mod.SigChan:
			return
		case <-time.After(timeout):
			mod.getRepositoryEvents(mod.owner, mod.repository, since)

		}
		since = time.Now()
		timeout = time.Duration(time.Minute)
	}
}
696358
func (o *Observer) Start() {
	for {
		select {
		case evt := <-o.notify: // We have an event to observe
			if len(o.observers) == 0 {
				log.Printf("Ignoring event due to no observers: %s", evt.ID)
				continue
			}

			evtb, err := json.Marshal(evt)
			if err != nil {
				log.Printf("Error marshaling event: %s", err)
				continue
			}

			sse := []byte("event: " + evt.Type + "\ndata: ")
			sse = append(sse, append(evtb, []byte("\n\n")...)...)

			for n := range o.observers {
				n <- sse
			}

		case n := <-o.newObservers:
			o.observers[n] = true
		case n := <-o.closedObservers:
			delete(o.observers, n)

		case <-o.closed: // The Observer has been closed.
			return
		}
	}
}
561057
func (c *StatsdClient) SendEvents(events map[string]event.Event) error {
	if c.conn == nil {
		return errNotConnected
	}

	var n int
	var stats = make([]string, 0)

	for _, e := range events {
		for _, stat := range e.Stats() {

			stat = c.prefix + strings.Replace(stat, "%HOST%", Hostname, 1)
			_n := n + len(stat) + 1

			if _n > UDPPayloadSize {
				// with this last event, the UDP payload would be too big
				if _, err := fmt.Fprintf(c.conn, strings.Join(stats, "\n")+"\n"); err != nil {
					return err
				}
				// reset payload after flushing, and add the last event
				stats = []string{stat}
				n = len(stat)
				continue
			}

			// can fit more into the current payload
			n = _n
			stats = append(stats, stat)
		}
	}

	if len(stats) != 0 {
		if _, err := fmt.Fprintf(c.conn, strings.Join(stats, "\n")+"\n"); err != nil {
			return err
		}
	}

	return nil
}
258631
func (r *BotService) Events(botId string) *BotEventsCall {
	c := &BotEventsCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	c.botId = botId
	return c
}