diff --git a/services/redis/mgmt/2020-06-01/redis/models.go b/services/redis/mgmt/2020-06-01/redis/models.go index 9138fefc4ed8..74572a735183 100644 --- a/services/redis/mgmt/2020-06-01/redis/models.go +++ b/services/redis/mgmt/2020-06-01/redis/models.go @@ -20,12 +20,13 @@ package redis import ( "context" "encoding/json" + "net/http" + "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/date" "github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/tracing" - "net/http" ) // The package's fully qualified name. @@ -95,30 +96,10 @@ func (cp CommonProperties) MarshalJSON() ([]byte, error) { // CreateFuture an abstraction for monitoring and retrieving the results of a long-running operation. type CreateFuture struct { - azure.Future -} - -// Result returns the result of the asynchronous operation. -// If the operation has not completed it will return an error. -func (future *CreateFuture) Result(client Client) (rt ResourceType, err error) { - var done bool - done, err = future.DoneWithContext(context.Background(), client) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.CreateFuture", "Result", future.Response(), "Polling failure") - return - } - if !done { - err = azure.NewAsyncOpIncompleteError("redis.CreateFuture") - return - } - sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) - if rt.Response.Response, err = future.GetResult(sender); err == nil && rt.Response.Response.StatusCode != http.StatusNoContent { - rt, err = client.CreateResponder(rt.Response.Response) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.CreateFuture", "Result", rt.Response.Response, "Failure responding to request") - } - } - return + azure.FutureAPI + // Result returns the result of the asynchronous operation. + // If the operation has not completed it will return an error. + Result func(client Client) (rt ResourceType, err error) } // CreateParameters parameters supplied to the Create Redis operation. diff --git a/services/redis/mgmt/2020-06-01/redis/redis.go b/services/redis/mgmt/2020-06-01/redis/redis.go index d4e904a08273..730e50b8c20a 100644 --- a/services/redis/mgmt/2020-06-01/redis/redis.go +++ b/services/redis/mgmt/2020-06-01/redis/redis.go @@ -19,11 +19,12 @@ package redis import ( "context" + "net/http" + "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/validation" "github.com/Azure/go-autorest/tracing" - "net/http" ) // Client is the REST API for Azure Redis Cache Service. @@ -162,7 +163,7 @@ func (client Client) Create(ctx context.Context, resourceGroupName string, name result, err = client.CreateSender(req) if err != nil { - err = autorest.NewErrorWithError(err, "redis.Client", "Create", result.Response(), "Failure sending request") + err = autorest.NewErrorWithError(err, "redis.Client", "Create", nil, "Failure sending request") return } @@ -194,14 +195,36 @@ func (client Client) CreatePreparer(ctx context.Context, resourceGroupName strin // CreateSender sends the Create request. The method will close the // http.Response Body if it receives an error. -func (client Client) CreateSender(req *http.Request) (future CreateFuture, err error) { +func (client Client) CreateSender(req *http.Request) (CreateFuture, error) { var resp *http.Response - resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + resp, err := client.Send(req, azure.DoRetryWithRegistration(client.Client)) if err != nil { - return - } - future.Future, err = azure.NewFutureFromResponse(resp) - return + return CreateFuture{}, err + } + future, err := azure.NewFutureFromResponse(resp) + return CreateFuture{ + FutureAPI: &future, + Result: func(client Client) (rt ResourceType, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "redis.CreateFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("redis.CreateFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if rt.Response.Response, err = future.GetResult(sender); err == nil && rt.Response.Response.StatusCode != http.StatusNoContent { + rt, err = client.CreateResponder(rt.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "redis.CreateFuture", "Result", rt.Response.Response, "Failure responding to request") + } + } + return + }, + }, err } // CreateResponder handles the response to the Create request. The method always