Skip to content

Commit

Permalink
Compatibility for Crystal 0.23.1 and later versions at once
Browse files Browse the repository at this point in the history
In versions after Crystal 0.23.1, Object#hash was changed to return
an UInt64 instead of a Int32.

This patch always forces hashes to use UInt64.
  • Loading branch information
Papierkorb committed Nov 8, 2017
1 parent 6f22fdb commit de54cc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/cute.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ require "./cute/version"
# Easy to use event-oriented publisher/subscribe modelled after the
# Qt Framework.
module Cute
# Type of a connection handle, as returned by the `#on` method of signals and
# `#add` of middlewares.
alias ConnectionHandle = UInt64

# Creates a *signal*. A signal manages listeners (So called *slots*), which
# will be called when an event has been *emitted*. Emitting is the act of
# triggering a signal to announce an event to the listeners.
Expand Down Expand Up @@ -246,15 +250,15 @@ module Cute
end

# Appends a middleware handler
def add(&block : Handler)
def add(&block : Handler) : ::Cute::ConnectionHandle
@listeners << block
block.hash
block.hash.to_u64
end

# Appends *handler*
def add(handler : Handler)
def add(handler : Handler) : ::Cute::ConnectionHandle
@listeners << handler
handler.hash
handler.hash.to_u64
end

# Calls the middleware chain.
Expand Down
6 changes: 3 additions & 3 deletions src/cute/signal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ module Cute
{{ call.name.stringify }}
end

def on(&block : {{ handler_type.id }})
def on(&block : {{ handler_type.id }}) : ::Cute::ConnectionHandle
@listeners << block
block.hash
block.hash.to_u64
end

def on(sink : Cute::Sink(U)) forall U
Expand All @@ -81,7 +81,7 @@ module Cute
{% if async %}end{% end %}
end

def new_channel : Tuple({{ channel_type.id }}, Int32)
def new_channel : Tuple({{ channel_type.id }}, ::Cute::ConnectionHandle)
ch = {{ channel_type.id }}.new

handle = {% if call.args.empty? %}
Expand Down

0 comments on commit de54cc1

Please sign in to comment.