When a time-dependent condition is met, resolve a promise.
await whenDo(() => testIsTrue);
// ...
await whenTimeout(() => window.L, 'Leaflet');
// Use Leaflet (L).
const map = L.map('map').setView([51.505, -0.09], 13);
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>