start.go 514 B

123456789101112131415161718192021222324252627
  1. //go:build darwin || windows
  2. package cmd
  3. import (
  4. "context"
  5. "errors"
  6. "time"
  7. "github.com/ollama/ollama/api"
  8. )
  9. func waitForServer(ctx context.Context, client *api.Client) error {
  10. // wait for the server to start
  11. timeout := time.After(5 * time.Second)
  12. tick := time.Tick(500 * time.Millisecond)
  13. for {
  14. select {
  15. case <-timeout:
  16. return errors.New("timed out waiting for server to start")
  17. case <-tick:
  18. if err := client.Heartbeat(ctx); err == nil {
  19. return nil // server has started
  20. }
  21. }
  22. }
  23. }