david_Yakhin_312 GroupWork 10846
Алмаз Сейтхазин (КФ МГУ, кафедра НДС) GroupWork 10848
t1import asynciot1import asyncio
22
3class Loop:3class Loop:
4    _funcs = []4    _funcs = []
5    _stop = False5    _stop = False
6    _count = 06    _count = 0
77
8    def __init__(self):8    def __init__(self):
9        self.idx = Loop._count9        self.idx = Loop._count
10        Loop._count += 110        Loop._count += 1
11        Loop._funcs.append(None)11        Loop._funcs.append(None)
1212
13    def __call__(self, func):13    def __call__(self, func):
14        Loop._funcs[self.idx] = func14        Loop._funcs[self.idx] = func
1515
16        async def wrapper(*args, **kwargs):16        async def wrapper(*args, **kwargs):
17            if Loop._stop:17            if Loop._stop:
18                return None18                return None
19            my_counter = 019            my_counter = 0
20            while True:20            while True:
21                if Loop._stop:21                if Loop._stop:
22                    return None22                    return None
23                result = await func(*args, **kwargs)23                result = await func(*args, **kwargs)
24                my_counter += 124                my_counter += 1
25                if result is None:25                if result is None:
26                    Loop._stop = True26                    Loop._stop = True
27                    return None27                    return None
28                await asyncio.sleep(0)28                await asyncio.sleep(0)
29        return wrapper29        return wrapper
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op