Actually, if you're dealing with a bunch of tracks in a tracklist,
Promise.all() makes the most sense, because you can't do async functions inside a read lock callback
(note to self: add that to the docs). Here's a sample:
Code: Select all
(async () => {
let promises = [];
fastForEach(t, (track) => {
promises.push(track.getExtendedTagsAsync());
});
let tagsList = await Promise.all(promises);
console.log(tagsList);
})();
In this case, it's safe to use
fastForEach because you don't need to cache the Track objects themselves; you only have to cache the getExtendedTagsAsync promises.
If you are worried about optimization, you
could check for the
longTextLoaded attribute and then use getExtendedTagsSync, but again I would not recommend it.
Actually, if you're dealing with a bunch of tracks in a tracklist, [b]Promise.all()[/b] makes the most sense, because you can't do async functions inside a read lock callback [i](note to self: add that to the docs)[/i]. Here's a sample:
[code]
(async () => {
let promises = [];
fastForEach(t, (track) => {
promises.push(track.getExtendedTagsAsync());
});
let tagsList = await Promise.all(promises);
console.log(tagsList);
})();
[/code]
In this case, it's safe to use [b]fastForEach[/b] because you don't need to cache the Track objects themselves; you only have to cache the getExtendedTagsAsync promises.
If you are worried about optimization, you [i]could[/i] check for the [b]longTextLoaded[/b] attribute and then use getExtendedTagsSync, but again I would not recommend it.