From 0cf2640c863898fb3a78f19be2d87f29f2ba677f Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Fri, 27 Aug 2021 18:14:10 -0400 Subject: [PATCH] better docs and stop ticker --- internal/codespaces/states.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/codespaces/states.go b/internal/codespaces/states.go index ed41fab9b..5c3dcef45 100644 --- a/internal/codespaces/states.go +++ b/internal/codespaces/states.go @@ -31,8 +31,9 @@ type PostCreateState struct { Status PostCreateStateStatus `json:"status"` } -// PollPostCreateStates polls the state file in a codespace after creation and calls the poller -// with a slice of states to be processed. +// PollPostCreateStates watches for state changes in a codespace, +// and calls the supplied poller for each batch of state changes. +// It runs until the context is cancelled or SSH tunnel is closed. func PollPostCreateStates(ctx context.Context, log logger, apiClient *api.API, user *api.User, codespace *api.Codespace, poller func([]PostCreateState)) error { token, err := apiClient.GetCodespaceToken(ctx, user.Login, codespace.Name) if err != nil { @@ -50,6 +51,8 @@ func PollPostCreateStates(ctx context.Context, log logger, apiClient *api.API, u } t := time.NewTicker(1 * time.Second) + defer t.Stop() + for { select { case <-ctx.Done():