Preskoči na glavni sadržaj
🔒 Način pregleda. Prvih petnaest Foundations lekcija je besplatno; ova je Pro. Pokrenite 7-dnevni trial da otključate editor, AI savjete i ostatak programa. Kartica obavezna, otkažite bilo kada u Dashboard.Pokreni 7-dnevni trial →
← KolegijiSenior Deep-DivesModul 1 · Konkurentnost i asinkroni interniasyncio: petlja događaja duboko zaranjanjepredict3 / 161
+100 XP
Zadatak🌐 shown in EN
📝 **Task:** Predict the 5-line interleave from `asyncio.gather(fetch('A', 1), fetch('B', 2))`. Both fetches print 'start NAME' first, then 'done NAME' after their await — and gather prints the result list last. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predvidi izlaz

Pažljivo pročitaj kod

import asyncio

async def fetch(name, delay):
    print(f"start {name}")
    await asyncio.sleep(delay)
    print(f"done {name}")
    return name

async def main():
    results = await asyncio.gather(
        fetch("A", 1),   # sleeps 1 s
        fetch("B", 2),   # sleeps 2 s
    )
    print(results)

asyncio.run(main())

# What does this print? Type your prediction.
# Hint: both fetches enter immediately (gather schedules them
# together). A finishes first (shorter sleep). The list at the end
# matches the ORDER the tasks were passed to gather, NOT the
# completion order.

Što će program ispisati? Napiši ovdje: