Add 6.12 theory files

This commit is contained in:
pro100ton 2024-11-19 23:38:11 +03:00
parent 0ee735b8a6
commit ca9fd45ea1
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,22 @@
import asyncio
async def async_operation():
print("Асинхронная операция началась...")
await asyncio.sleep(2)
print("Асинхронная операция завершена.")
return "Результат асинхронной операции"
def on_completion(task): # Callback-функция
result = task.result()
print(f"Callback функция вызвана. Получен результат: {result}")
async def main():
task = asyncio.create_task(async_operation())
task.add_done_callback(on_completion) # Регистрация callback-функции
await task
asyncio.run(main())

View file

@ -0,0 +1,22 @@
from typing import Callable
def greeting(name):
return f"Привет, {name}!"
def farewell(name):
return f"Пока, {name}!"
def process_name(callback: Callable, name: str):
return callback(name)
name = "Студент"
greeting_result = process_name(greeting, name)
print(greeting_result)
farewell_result = process_name(farewell, name)
print(farewell_result)