@@ -9,6 +9,8 @@ const logger = getLogger('stackTools:stackPrefetch');
99
1010const toolName = 'stackPrefetch' ;
1111const requestType = 'prefetch' ;
12+ const priority = 0 ;
13+ const addToBeginning = true ;
1214
1315let configuration = {
1416 maxImagesToPrefetch : Infinity ,
@@ -229,18 +231,32 @@ function prefetch(element) {
229231 imageIdsToPrefetch . push ( imageId ) ;
230232 }
231233 }
232- // Load images in reverse order, by adding them at the beginning of the pool.
233- for ( const imageToLoad of imageIdsToPrefetch . reverse ( ) ) {
234- if ( preventCache ) {
235- external . cornerstone
236- . loadImage ( imageToLoad , { priority : 0 , requestType } )
237- . then ( doneCallback , failCallback ) ;
238- } else {
239- external . cornerstone
240- . loadAndCacheImage ( imageToLoad , { priority : 0 , requestType } )
241- . then ( doneCallback , failCallback ) ;
242- }
234+
235+ let requestFn ;
236+ const options = {
237+ addToBeginning,
238+ priority,
239+ requestType,
240+ } ;
241+
242+ if ( preventCache ) {
243+ requestFn = id => external . cornerstone . loadImage ( id , options ) ;
244+ } else {
245+ requestFn = id => external . cornerstone . loadAndCacheImage ( id , options ) ;
243246 }
247+
248+ imageIdsToPrefetch . forEach ( imageId => {
249+ external . cornerstone . imageLoadPoolManager . addRequest (
250+ requestFn . bind ( null , imageId ) ,
251+ requestType ,
252+ // Additional details
253+ {
254+ imageId,
255+ } ,
256+ priority ,
257+ addToBeginning
258+ ) ;
259+ } ) ;
244260}
245261
246262function getPromiseRemovedHandler ( element ) {
0 commit comments