From 2c47a84540958b7a0cf4b8a26903db4cd4bb830c Mon Sep 17 00:00:00 2001 From: Oleksiy Kovyrin Date: Wed, 16 Oct 2024 11:38:07 -0400 Subject: [PATCH] Return wait_time and use it when yielding --- ext/semian/resource.c | 4 ++-- ext/semian/resource.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/semian/resource.c b/ext/semian/resource.c index 0be8fece..6ded69cd 100644 --- a/ext/semian/resource.c +++ b/ext/semian/resource.c @@ -68,7 +68,7 @@ semian_resource_acquire_semaphore(int argc, VALUE *argv, VALUE self) wait_time = LONG2NUM(res.wait_time); } - return Qnil; + return wait_time; } VALUE @@ -78,7 +78,7 @@ semian_resource_acquire(int argc, VALUE *argv, VALUE self) rb_raise(rb_eArgError, "acquire requires a block"); } - semian_resource_acquire_semaphore(argc, argv, self); + VALUE wait_time = semian_resource_acquire_semaphore(argc, argv, self); return rb_ensure(rb_yield, wait_time, semian_resource_release_semaphore, self); } diff --git a/ext/semian/resource.h b/ext/semian/resource.h index 47f6f975..afbef41c 100644 --- a/ext/semian/resource.h +++ b/ext/semian/resource.h @@ -41,7 +41,7 @@ semian_resource_acquire(int argc, VALUE *argv, VALUE self); /* * call-seq: - * resource.acquire_semaphore(timeout: default_timeout) -> nil + * resource.acquire_semaphore(timeout: default_timeout) -> wait_time * * Acquires a resource. The call will block for timeout seconds if a ticket * is not available. If no ticket is available within the timeout period, Semian::TimeoutError