From 8cebfb4c9d9d8c216a8845eb0ad0b25b7deff28d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 16 Jun 2023 15:15:49 +0400 Subject: [PATCH] cli: Replace looped `time.Sleep` with `time.Timer` Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/container/create.go | 9 ++++++--- cmd/neofs-cli/modules/container/delete.go | 9 ++++++--- cmd/neofs-cli/modules/container/set_eacl.go | 9 ++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cmd/neofs-cli/modules/container/create.go b/cmd/neofs-cli/modules/container/create.go index e1052f2776..a3eea1d0b5 100644 --- a/cmd/neofs-cli/modules/container/create.go +++ b/cmd/neofs-cli/modules/container/create.go @@ -135,13 +135,16 @@ It will be stored in sidechain when inner ring will accepts it.`, getPrm.SetClient(cli) getPrm.SetContainer(id) - for { - time.Sleep(1 * time.Second) + const waitInterval = time.Second + t := time.NewTimer(waitInterval) + defer t.Stop() + + for ; ; t.Reset(waitInterval) { select { case <-ctx.Done(): common.ExitOnErr(cmd, "", errCreateTimeout) - default: + case <-t.C: } _, err := internalclient.GetContainer(ctx, getPrm) diff --git a/cmd/neofs-cli/modules/container/delete.go b/cmd/neofs-cli/modules/container/delete.go index 2f42edcef5..1e05737193 100644 --- a/cmd/neofs-cli/modules/container/delete.go +++ b/cmd/neofs-cli/modules/container/delete.go @@ -107,13 +107,16 @@ Only owner of the container has a permission to remove container.`, getPrm.SetClient(cli) getPrm.SetContainer(id) - for { - time.Sleep(1 * time.Second) + const waitInterval = time.Second + t := time.NewTimer(waitInterval) + defer t.Stop() + + for ; ; t.Reset(waitInterval) { select { case <-ctx.Done(): common.ExitOnErr(cmd, "", errDeleteTimeout) - default: + case <-t.C: } _, err := internalclient.GetContainer(ctx, getPrm) diff --git a/cmd/neofs-cli/modules/container/set_eacl.go b/cmd/neofs-cli/modules/container/set_eacl.go index 9cfef7e9cd..446ce39f97 100644 --- a/cmd/neofs-cli/modules/container/set_eacl.go +++ b/cmd/neofs-cli/modules/container/set_eacl.go @@ -74,13 +74,16 @@ Container ID in EACL table will be substituted with ID from the CLI.`, getEACLPrm.SetClient(cli) getEACLPrm.SetContainer(id) - for { - time.Sleep(1 * time.Second) + const waitInterval = time.Second + t := time.NewTimer(waitInterval) + defer t.Stop() + + for ; ; t.Reset(waitInterval) { select { case <-ctx.Done(): common.ExitOnErr(cmd, "", errSetEACLTimeout) - default: + case <-t.C: } res, err := internalclient.EACL(ctx, getEACLPrm)