From f36e14e3f0127d6ae064b217f898920de340984b Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 12 Feb 2025 23:21:43 +0200 Subject: [PATCH] using defer for releaseing lock --- library/waku_thread/waku_thread.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/waku_thread/waku_thread.nim b/library/waku_thread/waku_thread.nim index e7487a3182..d585b66373 100644 --- a/library/waku_thread/waku_thread.nim +++ b/library/waku_thread/waku_thread.nim @@ -104,27 +104,25 @@ proc sendRequestToWakuThread*( # Rearchitecting the signaling + migrating to a MP Channel will allow us to receive # requests concurrently and spare us the need of locks ctx.lock.acquire() + defer: + ctx.lock.release() ## Sending the request let sentOk = ctx.reqChannel.trySend(req) if not sentOk: - ctx.lock.release() deallocShared(req) return err("Couldn't send a request to the waku thread: " & $req[]) let fireSyncRes = ctx.reqSignal.fireSync() if fireSyncRes.isErr(): - ctx.lock.release() deallocShared(req) return err("failed fireSync: " & $fireSyncRes.error) if fireSyncRes.get() == false: - ctx.lock.release() deallocShared(req) return err("Couldn't fireSync in time") ## wait until the Waku Thread properly received the request let res = ctx.reqReceivedSignal.waitSync() - ctx.lock.release() if res.isErr(): deallocShared(req)