import asyncio
from typing import Any, Dict


class ADict:

    def __init__(self):
        self.data: Dict[str, asyncio.Future] = {}
        self.lock = asyncio.Lock()

    async def get(self, key: str) -> Any:
        if key in self.data:
            async with self.lock:
                return await self.data[key]

        self.data[key] = asyncio.Future()
        return await self.data[key]

    async def set(self, key: str, value: Any) -> None:
        async with self.lock:
            if key in self.data:
                f = self.data[key]
            else:
                f = asyncio.Future()
            f.set_result(value)
            self.data[key] = f

    def __str__(self):
        return f'ADict({self.data})'


async def show_amount(a_dict: ADict, key: str):
    amount = await a_dict.get(key)
    print(f'GOT: {amount} for {key}')


async def test():
    print('TEST START')
    a_dict = ADict()
    asyncio.create_task(show_amount(a_dict, 'Moscow'))
    await asyncio.sleep(1)
    await a_dict.set('Moscow', 200000)
    await a_dict.set('Spb', 150000)
    print(a_dict)
    await asyncio.sleep(1)
    asyncio.create_task(show_amount(a_dict, 'Moscow'))
    asyncio.create_task(show_amount(a_dict, 'Spb'))
    await asyncio.sleep(1)
    print(a_dict)
    print('TEST END')


asyncio.run(test())