Skip to content

Conversation

@slampy97
Copy link
Contributor

No description provided.

self._req_id = None

async def acquire(self):
return await self.__aenter__()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

должно быть наоборот, в enter мы должны вызывать acquire, а в exit - release.

async def release(self):
await self.__aexit__(None, None, None)

async def create(self, init_limit, init_data):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне кажется все методы, кроме acquire и release (ну и возможно close) должны быть непубличными, то есть с приставкой _ перед названием метода. Подумай, при каких сценариях вообще пользователю нужно будет вызывать условный create или delete?


self._stream = self._reconnector.get_stream()

async def _wait_for_response(self, req_id: int, *, kind: str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот метод выглядит странным. по наличию while True он похож на какой-то бекграунд луп, однако вызываем мы его на каждый вызов
сейчас возможна ситуация, где мы в параллель запустим два запроса и получим в каждом из них противоречивые ответы
у тебя есть req_id, по нему ты можешь однозначно определить нужный тебе респонз, нам не нужно для этого каждый раз инициировать опрос сервера, можно делать это в фоне и синкаться по req_id

self,
client,
name: str,
node_path: Optional[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему тут есть какой-то дефолтно пустой node_path?

lock = client.lock("test_lock", node_path)

create_resp: CreateSemaphoreResult = await lock.create(init_limit=1, init_data=b"init-data")
assert create_resp.status == StatusCode.SUCCESS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем это пользователю? в случае ошибки мы получим эксепшн, в случае успеха - нет

lock2_acquired.set()
await asyncio.sleep(0.5)

async with client.lock("test_lock", node_path) as lock1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

очень сложно это все читать. давай будем пользоваться методами acquire и release, а также не будем делать этот километровый дескрайб

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants