OK - I've a site I wrote years back which did work, but now due to a data centre move I realise it onl;y worked becasue the requests were resolved quickly, on the "new" network my code needs attention for timing.
I have this
dojo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">connect</SPAN><SPAN class="punctuation token">(</SPAN>dynamicMapServiceLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"onLoad"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> content <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="comment token">//return the layer descriptions and © text into arrays - we use this later for the info dialog to generate hyperlinks and © text</SPAN>
dojo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">forEach</SPAN><SPAN class="punctuation token">(</SPAN>dynamicMapServiceLayer<SPAN class="punctuation token">.</SPAN>layerInfos<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//console.debug(dynamicMapServiceLayer.layerInfos[layer.id])</SPAN>
<SPAN class="keyword token">var</SPAN> requestHandle <SPAN class="operator token">=</SPAN> esri<SPAN class="punctuation token">.</SPAN><SPAN class="token function">request</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
url<SPAN class="punctuation token">:</SPAN> mapserviceCustom <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/"</SPAN> <SPAN class="operator token">+</SPAN> layer<SPAN class="punctuation token">.</SPAN>id <SPAN class="operator token">+</SPAN> <SPAN class="string token">"?f=json"</SPAN><SPAN class="punctuation token">,</SPAN>
handleAs<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"json"</SPAN><SPAN class="punctuation token">,</SPAN>
load<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
LayerAttach<SPAN class="punctuation token">[</SPAN>layer<SPAN class="punctuation token">.</SPAN>id<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">.</SPAN>hasAttachments<SPAN class="punctuation token">;</SPAN>
LayerDescriptions<SPAN class="punctuation token">[</SPAN>layer<SPAN class="punctuation token">.</SPAN>id<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">.</SPAN>description<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//LayerCopyright[layer.id] = data.copyrightText;</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">debug</SPAN><SPAN class="punctuation token">(</SPAN>dynamicMapServiceLayer<SPAN class="punctuation token">)</SPAN>
dynamicMapServiceLayer<SPAN class="punctuation token">.</SPAN>layerInfos<SPAN class="punctuation token">[</SPAN>layer<SPAN class="punctuation token">.</SPAN>id<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>copyrightText <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">.</SPAN>copyrightText<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> useProxy<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">true</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>That runs during the init of my site and gets more info from the REST of the service regarding each layer, I use this to dynamically control the copyright notice on the map, as this varies per layer. I store this info in the layer description.
I've not looked at this for a long time, but I know I need to do something to stop the rest of the code working until all this has run, as a later part of my init code will use the results - but my hack skills are exhausted. Most of the site is in legacy and most examples I have found are in AMD. So any help gratefully received.
Cheers
ACM