Skip to content

Commit

Permalink
Make Thread::Queue and Thread::SizedQueue generic
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Sep 5, 2024
1 parent 2a6e27b commit b89b05b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/thread.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ end
#
# consumer.join
#
class Thread::Queue < Object
class Thread::Queue[T = untyped] < Object
# <!-- rdoc-file=thread_sync.c -->
# Pushes the given `object` to the queue.
#
Expand Down Expand Up @@ -1661,7 +1661,8 @@ class Thread::Queue < Object
# If `timeout` seconds have passed and no data is available `nil` is returned.
# If `timeout` is `0` it returns immediately.
#
def pop: (?boolish non_block, ?timeout: _ToF?) -> untyped
def pop: (?boolish non_block) -> T
| (?boolish nonblock, timeout: _ToF?) -> T?

# <!--
# rdoc-file=thread_sync.c
Expand All @@ -1671,7 +1672,7 @@ class Thread::Queue < Object
# -->
# Pushes the given `object` to the queue.
#
def push: (untyped obj) -> void
def push: (T obj) -> void

# <!--
# rdoc-file=thread_sync.rb
Expand All @@ -1692,7 +1693,7 @@ end
#
# See Thread::Queue for an example of how a Thread::SizedQueue works.
#
class Thread::SizedQueue < Thread::Queue
class Thread::SizedQueue[T = untyped] < Thread::Queue[T]
# <!--
# rdoc-file=thread_sync.rb
# - <<(object, non_block = false, timeout: nil)
Expand Down Expand Up @@ -1755,7 +1756,8 @@ class Thread::SizedQueue < Thread::Queue
# If `timeout` seconds have passed and no space is available `nil` is returned.
# If `timeout` is `0` it returns immediately. Otherwise it returns `self`.
#
def push: (untyped obj, ?boolish non_block, timeout: _ToF?) -> void
def push: (T obj, ?boolish non_block) -> void
| (T obj, ?boolish non_block, timeout: _ToF?) -> self?
end

class ConditionVariable = Thread::ConditionVariable
Expand Down

0 comments on commit b89b05b

Please sign in to comment.