Skip to content

Commit

Permalink
next function docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubwro committed Sep 20, 2024
1 parent a527c62 commit e6fc960
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/pubsub/subscribe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Subscribe to a subject in synchronous mode. Client is supposed to call `next` ma
Optional keyword arguments are:
- `queue_group`: NATS server will distribute messages across queue group members
- `channel_size`: maximum items buffered for processing, if full messages will be ignored, default is `$DEFAULT_SUBSCRIPTION_CHANNEL_SIZE`, can be configured globally with `NATS_SUBSCRIPTION_CHANNEL_SIZE` env variable
- `monitoring_throttle_seconds`: time intervals in seconds that handler errors will be reported in logs, default is `$DEFAULT_SUBSCRIPTION_ERROR_THROTTLING_SECONDS` seconds, can be configured globally with `NATS_SUBSCRIPTION_ERROR_THROTTLING_SECONDS` env variable
"""
function subscribe(
connection::Connection,
Expand Down Expand Up @@ -91,6 +92,8 @@ function subscribe(
end

"""
$(SIGNATURES)
Obtains next message for synchronous subscription.
Optional keyword arguments:
Expand Down Expand Up @@ -144,12 +147,30 @@ function next(connection::Connection, sub::Sub; no_wait = false, no_throw = fals
msg
end

"""
$(SIGNATURES)
Obtains next message for synchronous subscription converting it to requested `T` type.
Optional keyword arguments:
- `no_wait`: do not wait for next message, return `nothing` if buffer is empty
- `no_throw`: do not throw exception, returns `nothing` if cannot get next message
"""
function next(T::Type, connection::Connection, sub::Sub; no_wait = false, no_throw = false)::Union{T, Nothing}
find_msg_conversion_or_throw(T)
msg = next(connection, sub; no_wait, no_throw)
isnothing(msg) ? nothing : convert(T, msg) #TODO: invokelatest
end

"""
$(SIGNATURES)
Obtains batch of messages for synchronous subscription.
Optional keyword arguments:
- `no_wait`: do not wait for next message, return `nothing` if buffer is empty
- `no_throw`: do not throw exception, returns `nothing` if cannot get next message
"""
function next(connection::Connection, sub::Sub, batch::Integer; no_wait = false, no_throw = false)::Vector{Msg}
msgs = []
for i in 1:batch
Expand All @@ -160,6 +181,15 @@ function next(connection::Connection, sub::Sub, batch::Integer; no_wait = false,
msgs
end

"""
$(SIGNATURES)
Obtains batch of messages for synchronous subscription converting them to reqested `T` type.
Optional keyword arguments:
- `no_wait`: do not wait for next message, return `nothing` if buffer is empty
- `no_throw`: do not throw exception, returns `nothing` if cannot get next message
"""
function next(T::Type, connection::Connection, sub::Sub, batch::Integer; no_wait = false, no_throw = false)::Vector{T}
find_msg_conversion_or_throw(T)
convert.(T, next(connection, sub, batch; no_wait, no_throw)) #TODO: invokelatest
Expand Down

2 comments on commit e6fc960

@jakubwro
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/115613

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" e6fc9603f71f440b06f0a122b5dfd68a88906f47
git push origin v0.1.0

Please sign in to comment.