Skip to content

Commit 6d60f55

Browse files
authored
Merge branch 'main' into fix/shopify-ff
2 parents 6d20fa4 + 53be992 commit 6d60f55

File tree

86 files changed

+4674
-2866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4674
-2866
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,15 @@ public GetTaskResponse WaitForAppTask(long taskId, int maxRetries = DefaultMaxRe
7676
/// <summary>
7777
/// Helper method that waits for an API key task to be processed.
7878
/// </summary>
79-
/// <param name="operation">The `operation` that was done on a `key`.</param>
8079
/// <param name="key">The key that has been added, deleted or updated.</param>
80+
/// <param name="operation">The `operation` that was done on a `key`.</param>
8181
/// <param name="apiKey">Necessary to know if an `update` operation has been processed, compare fields of the response with it. (optional - mandatory if operation is UPDATE)</param>
8282
/// <param name="maxRetries">The maximum number of retry. 50 by default. (optional)</param>
8383
/// <param name="timeout">The function to decide how long to wait between retries. Math.Min(retryCount * 200, 5000) by default. (optional)</param>
8484
/// <param name="requestOptions">The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)</param>
8585
/// <param name="ct">Cancellation token (optional)</param>
86-
public async Task<GetApiKeyResponse> WaitForApiKeyAsync(ApiKeyOperation operation, string key,
86+
public async Task<GetApiKeyResponse> WaitForApiKeyAsync(string key,
87+
ApiKeyOperation operation,
8788
ApiKey apiKey = default, int maxRetries = DefaultMaxRetries, Func<int, int> timeout = null,
8889
RequestOptions requestOptions = null, CancellationToken ct = default)
8990
{
@@ -112,36 +113,35 @@ public async Task<GetApiKeyResponse> WaitForApiKeyAsync(ApiKeyOperation operatio
112113
}, maxRetries, timeout, ct).ConfigureAwait(false);
113114
}
114115

115-
var addedKey = new GetApiKeyResponse();
116-
117-
// check the status of the getApiKey method
118-
await RetryUntil(async () =>
116+
return await RetryUntil(async () =>
119117
{
120118
try
121119
{
122-
addedKey = await GetApiKeyAsync(key, requestOptions, ct).ConfigureAwait(false);
123-
// magic number to signify we found the key
124-
return -2;
120+
return await GetApiKeyAsync(key, requestOptions, ct).ConfigureAwait(false);
125121
}
126122
catch (AlgoliaApiException e)
127123
{
128-
return e.HttpErrorCode;
124+
if (e.HttpErrorCode is 404)
125+
{
126+
return null;
127+
}
128+
129+
throw;
129130
}
130-
}, (status) =>
131+
}, (response) =>
131132
{
132133
return operation switch
133134
{
134135
ApiKeyOperation.Add =>
135136
// stop either when the key is created or when we don't receive 404
136-
status is -2 or not 404 and not 0,
137+
response is not null,
137138
ApiKeyOperation.Delete =>
138139
// stop when the key is not found
139-
status == 404,
140+
response is null,
140141
_ => false
141142
};
142143
},
143144
maxRetries, timeout, ct);
144-
return addedKey;
145145
}
146146

147147
/// <summary>
@@ -154,10 +154,10 @@ await RetryUntil(async () =>
154154
/// <param name="timeout">The function to decide how long to wait between retries. Math.Min(retryCount * 200, 5000) by default. (optional)</param>
155155
/// <param name="requestOptions">The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)</param>
156156
/// <param name="ct">Cancellation token (optional)</param>
157-
public GetApiKeyResponse WaitForApiKey(ApiKeyOperation operation, string key, ApiKey apiKey = default,
157+
public GetApiKeyResponse WaitForApiKey(string key, ApiKeyOperation operation, ApiKey apiKey = default,
158158
int maxRetries = DefaultMaxRetries, Func<int, int> timeout = null, RequestOptions requestOptions = null,
159159
CancellationToken ct = default) =>
160-
AsyncHelper.RunSync(() => WaitForApiKeyAsync(operation, key, apiKey, maxRetries, timeout, requestOptions, ct));
160+
AsyncHelper.RunSync(() => WaitForApiKeyAsync(key, operation, apiKey, maxRetries, timeout, requestOptions, ct));
161161

162162

163163
/// <summary>

0 commit comments

Comments
 (0)