Let's say I want to print "Main" before printing "Foo".
In Lua, it can be achieved with this code:
local function sleep(sec)
local start_sleep = os.clock()
while os.clock() - start_sleep <= sec do
end
end
local function foo()
sleep(2)
print("Foo")
end
local function main()
coroutine.wrap(foo)()
print("Main")
end
main()
--[[
// Output:
Main
-- waits 2 seconds
Foo
]]
But if I try to implement it in Python it does:
import asyncio
async def foo():
await asyncio.sleep(2)
print("Foo")
def main():
asyncio.run(foo())
print("Main")
main()
"""
// Output:
-- waits 2 seconds
Foo
Main
"""
As I am really a beginner at Python, I would like to know how could I achieve it with Python.