@@ -200,33 +200,25 @@ func newWindowsDesktopCollection(upstream services.WindowsDesktops, w types.Watc
200200				},
201201			}),
202202		fetcher : func (ctx  context.Context , loadSecrets  bool ) ([]types.WindowsDesktop , error ) {
203- 			var  start  string 
204- 			var  desktops  []types.WindowsDesktop 
205- 			for  {
206- 				req  :=  types.ListWindowsDesktopsRequest {
207- 					// A non zero limit is required by older versions. 
208- 					Limit :    defaults .DefaultChunkSize ,
209- 					StartKey : start ,
210- 				}
211- 
212- 				resp , err  :=  upstream .ListWindowsDesktops (ctx , req )
213- 				if  err  !=  nil  {
214- 					// TODO(tross): DELETE in V21.0.0 
215- 					if  trace .IsNotImplemented (err ) {
216- 						return  upstream .GetWindowsDesktops (ctx , types.WindowsDesktopFilter {})
203+ 			// TODO(tross): DELETE in V21.0.0  replace by regular clientutils.Resources 
204+ 			out , err  :=  clientutils .CollectWithFallback (
205+ 				ctx ,
206+ 				func (ctx  context.Context , limit  int , start  string ) ([]types.WindowsDesktop , string , error ) {
207+ 					resp , err  :=  upstream .ListWindowsDesktops (ctx , types.ListWindowsDesktopsRequest {
208+ 						Limit :    limit ,
209+ 						StartKey : start ,
210+ 					})
211+ 					if  err  !=  nil  {
212+ 						return  nil , "" , trace .Wrap (err )
217213					}
214+ 					return  resp .Desktops , resp .NextKey , nil 
215+ 				},
216+ 				func (ctx  context.Context ) ([]types.WindowsDesktop , error ) {
217+ 					return  upstream .GetWindowsDesktops (ctx , types.WindowsDesktopFilter {})
218+ 				},
219+ 			)
218220
219- 					return  nil , trace .Wrap (err )
220- 				}
221- 
222- 				desktops  =  append (desktops , resp .Desktops ... )
223- 				start  =  resp .NextKey 
224- 				if  resp .NextKey  ==  ""  {
225- 					break 
226- 				}
227- 			}
228- 
229- 			return  desktops , nil 
221+ 			return  out , trace .Wrap (err )
230222		},
231223		headerTransform : func (hdr  * types.ResourceHeader ) types.WindowsDesktop  {
232224			return  & types.WindowsDesktopV3 {
0 commit comments