Skip to content

Commit df7292f

Browse files
committed
#21-Python
1 parent 09f0847 commit df7292f

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# 21 - Callbacks
2+
3+
import asyncio
4+
import random
5+
6+
def end_process():
7+
print("Proceso terminado.")
8+
9+
def count_number(num, fun):
10+
for i in range(num):
11+
print(i+1)
12+
fun()
13+
14+
count_number(6,end_process)
15+
16+
def greeting_process(callback, name):
17+
print("Ejecutando el proceso de saludo....")
18+
callback(name)
19+
20+
def greet_callback(name: str):
21+
print(f"Hola {name}!")
22+
23+
greeting_process(greet_callback, "Gordo Master")
24+
25+
"""
26+
Ejercicio Extra
27+
"""
28+
29+
async def confir(name):
30+
print(f"Pedido de: {name} confirmado")
31+
32+
async def order_ok(name):
33+
print(f"Pedido de: {name} esta listo")
34+
35+
async def delivered(name):
36+
print(f"Pedido de: {name} fue entregado")
37+
38+
async def order(name,confir_callback,order_ok_callback,delivered_callback):
39+
await confir_callback(name)
40+
await asyncio.sleep(random.randint(1,10))
41+
42+
await order_ok_callback(name)
43+
await asyncio.sleep(random.randint(1,10))
44+
45+
await delivered_callback(name)
46+
47+
async def main():
48+
await asyncio.gather(
49+
order("Hamburguesa",confir,order_ok,delivered),
50+
order("Papas fritas",confir,order_ok,delivered),
51+
order("Gaseosa",confir,order_ok,delivered),
52+
order("Helado",confir,order_ok,delivered)
53+
)
54+
55+
asyncio.run(main())

0 commit comments

Comments
 (0)