File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,12 @@ namespace ReadyPlayerMe.AvatarCreator
10
10
/// </summary>
11
11
public class AvatarTemplateFetcher
12
12
{
13
+ private readonly CancellationToken ctx ;
13
14
private readonly AvatarAPIRequests avatarAPIRequests ;
14
15
15
16
public AvatarTemplateFetcher ( CancellationToken ctx = default )
16
17
{
18
+ this . ctx = ctx ;
17
19
avatarAPIRequests = new AvatarAPIRequests ( ctx ) ;
18
20
}
19
21
@@ -34,21 +36,26 @@ public async Task<List<AvatarTemplateData>> GetTemplates()
34
36
public async Task < List < AvatarTemplateData > > GetTemplatesWithRenders ( )
35
37
{
36
38
var templates = await avatarAPIRequests . GetAvatarTemplates ( ) ;
37
- await FetchTemplateRenders ( templates ) ;
38
- return templates ;
39
+ return await FetchTemplateRenders ( templates ) ;
39
40
}
40
41
41
42
/// <summary>
42
43
/// Fetches the renders for all the templates provided.
43
44
/// </summary>
44
- public async Task FetchTemplateRenders ( List < AvatarTemplateData > templates )
45
+ public async Task < List < AvatarTemplateData > > FetchTemplateRenders ( List < AvatarTemplateData > templates )
45
46
{
46
47
var tasks = templates . Select ( async templateData =>
47
48
{
48
49
templateData . Texture = await avatarAPIRequests . GetAvatarTemplateImage ( templateData . ImageUrl ) ;
49
- } ) ;
50
+ } ) . ToList ( ) ;
51
+
52
+ while ( ! tasks . All ( x => x . IsCompleted ) &&
53
+ ! ctx . IsCancellationRequested )
54
+ {
55
+ await Task . Yield ( ) ;
56
+ }
50
57
51
- await Task . WhenAll ( tasks ) ;
58
+ return templates ;
52
59
}
53
60
}
54
61
}
You can’t perform that action at this time.
0 commit comments