// RunUntilSuccess tries to run `f` function most `n` times until `f` return true, else return false
764808
func RunUntilSuccess(n int, f func() bool, retryInterval time.Duration) bool {
	for i := 0; i < n; i++ {
		if f() {
			return true
		}

		time.Sleep(retryInterval)
	}

	return false
}
471192
func (g *lockedNetNSGoroutine) run(f func()) {
	done := make(chan struct{})
	g.funcC <- func() {
		defer close(done)
		f()
	}
	<-done
}
63578
func (sc *syncClient) run() error {
	for {
		select {
		case <-sc.stopped:
			<-sc.start
			log.Infof("Starting sync client...")
		default:
			sc.runOnce()
			select {
			case <-time.After(5 * time.Second):
			case <-sc.quit:
				sc.stopped <- true
			}
		}
	}
}
736864
func (v *CredentialAuthority) runWithCancel(body func(ctx context.Context) error) error {
	ctx, cancel := context.WithCancel(context.Background())
	doneCh := make(chan error)
	var err error

	go func() {
		doneCh <- body(ctx)
	}()

	select {
	case err = <-doneCh:
	case <-v.shutdownCh:
		cancel()
		err = ErrShutdown
	}
	return err
}
1034973
func (l *lexer) run() {
	for l.state = lexTop; l.state != nil; {
		l.state = l.state(l)
	}
}
349349
func (c *Client) run() {
	// Watch for changes in allocations
	allocUpdates := make(chan *allocUpdates, 8)
	go c.watchAllocations(allocUpdates)

	for {
		select {
		case update := <-allocUpdates:
			// Don't apply updates while shutting down.
			c.shutdownLock.Lock()
			if c.shutdown {
				c.shutdownLock.Unlock()
				return
			}

			// Apply updates inside lock to prevent a concurrent
			// shutdown.
			c.runAllocs(update)
			c.shutdownLock.Unlock()

		case <-c.shutdownCh:
			return
		}
	}
}
945147
func (c *CmdSimpleFSCopy) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	ctx := context.TODO()

	c.G().Log.Debug("SimpleFSCopy (recursive: %v) to: %s", c.recurse, c.dest)

	destPaths, err := doSimpleFSGlob(ctx, c.G(), cli, c.src)
	if err != nil {
		return err
	}

	// Eat the error because it's ok here if the dest doesn't exist
	isDestDir, destPathString, _ := checkPathIsDir(ctx, cli, c.dest)

	for _, src := range destPaths {
		var dest keybase1.Path
		dest, err = makeDestPath(ctx, c.G(), cli, src, c.dest, isDestDir, destPathString)
		c.G().Log.Debug("SimpleFSCopy %s -> %s, %v", src, dest, isDestDir)

		if err == ErrTargetFileExists {
			if c.interactive == true {
				err = doOverwritePrompt(c.G(), dest.String())
			} else if c.force == true {
				err = nil
			}
		}

		if err != nil {
			c.G().Log.Debug("SimpleFSCopy can't get paths together")
			return err
		}

		// Don't spawn new jobs if we've been cancelled.
		// TODO: This is still a race condition, if we get cancelled immediately after.
		if c.opCanceler.IsCancelled() {
			break
		}

		opid, err2 := cli.SimpleFSMakeOpid(ctx)
		if err2 != nil {
			return err2
		}
		c.opCanceler.AddOp(opid)

		if c.recurse {
			err = cli.SimpleFSCopyRecursive(ctx, keybase1.SimpleFSCopyRecursiveArg{
				OpID: opid,
				Src:  src,
				Dest: dest,
			})
		} else {
			err = cli.SimpleFSCopy(ctx, keybase1.SimpleFSCopyArg{
				OpID: opid,
				Src:  src,
				Dest: dest,
			})
		}
		if err != nil {
			break
		}

		err = cli.SimpleFSWait(ctx, opid)
		if err != nil {
			break
		}
	}
	return err
}
1345883
func isSuccessCode(statusCode int) bool {
	if statusCode >= http.StatusOK && statusCode < http.StatusMultipleChoices {
		return true
	}

	return false
}
834936
func RunFunc(benchmarkFunc func() int, duration time.Duration, c int) *Result {
	workers := make([]Worker, c)
	for i := 0; i < c; i++ {
		workers[i] = &funcWorker{ID: i, benchmarkFunc: benchmarkFunc}
	}
	return Run(workers, duration)
}
111952
func Run(s Server, signals ...os.Signal) {
	RunFunc(s.Serve, s.Close, signals...)
}
442271
func (m *RegeneratingDiscoveryRESTMapper) RunUntil(stop <-chan struct{}) {
	go wait.Until(func() {
		if err := m.RegenerateMappings(); err != nil {
			klog.Errorf("error regenerating REST mappings from discovery: %v", err)
		}
	}, m.refreshInterval, stop)
}
160594
func (v *Echo_Echo_Result) GetSuccess() (o *Pong) {
	if v != nil && v.Success != nil {
		return v.Success
	}

	return
}
416312
func (o TopImageStreamsOptions) Run() error {
	infos := o.imageStreamsTop()
	Print(o.Out, ImageStreamColumns, infos)
	return nil
}
901558
func (c *CmdSimpleFSKill) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	err = cli.SimpleFSClose(context.TODO(), c.opid)

	return err
}
998840
func (svc *Service) run() {

	// Wait for dependencies to start.
	for _, dep := range svc.dependencies {
		log.Infof("Service %s waiting for %s to start", svc.name, dep.name)
		select {
		case started := <-dep.started:
			dep.started <- started
		case <-svc.shutdown:
			goto done
		}
	}

	for {
		if svc.failures > 0 {
			delay := time.Duration(svc.failures) * restartBackoff
			if delay > restartBackoffMax {
				delay = restartBackoffMax
			}
			log.Infof("Service %s has failed %d times - delaying %s before restart",
				svc.name, svc.failures, delay)

			select {
			case <-time.After(delay):
			case <-svc.shutdown:
				goto done
			}
		}

		svc.restarts++
		svc.lastRestart = time.Now()
		svc.runOnce()

		select {
		case <-time.After(restartDelay):
		case <-svc.shutdown:
			goto done
		}
	}
done:
	svc.done <- true
}
831866
func (c *CmdSimpleFSMkdir) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	ctx := context.TODO()

	c.opid, err = cli.SimpleFSMakeOpid(ctx)
	if err != nil {
		return err
	}
	defer cli.SimpleFSClose(ctx, c.opid)
	err = cli.SimpleFSOpen(ctx, keybase1.SimpleFSOpenArg{
		OpID:  c.opid,
		Dest:  c.path,
		Flags: keybase1.OpenFlags_DIRECTORY,
	})
	if err != nil {
		return err
	}

	return err
}
618130
func RunFunc(runner ServeFunc, closer CloseFunc, signals ...os.Signal) {
	// subscribe signals
	stop := make(chan os.Signal, 1)
	if len(signals) == 0 {
		signals = []os.Signal{syscall.SIGINT, syscall.SIGTERM}
	}
	signal.Notify(stop, signals...)

	logger := log.Get(PkgName)
	go func() {
		if err := runner(); err != nil {
			logger.Fatal("app > ", err)
		}
	}()

	sig := <-stop // wait for signals
	logger.Info("app > Received signal: ", sig.String())
	logger.Info("app > Exiting program...")
	if closer != nil {
		closer(Timeout)
	}
	logger.Info("app > Program exited")
}