Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

crystal 0.27 compability #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/amqp/protocol.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module AMQP::Protocol
@reply_to = "",
@expiration = "",
@message_id = "",
@timestamp = Time.epoch(0),
@timestamp = Time::UNIX_EPOCH.as(Time),
@type = "",
@user_id = "",
@app_id = "",
Expand Down Expand Up @@ -174,7 +174,7 @@ module AMQP::Protocol
flags = flags | FLAG_REPLY_TO unless @reply_to.empty?
flags = flags | FLAG_EXPIRATION unless @expiration.empty?
flags = flags | FLAG_MESSAGE_ID unless @message_id.empty?
flags = flags | FLAG_TIMESTAMP unless @timestamp.epoch == 0
flags = flags | FLAG_TIMESTAMP unless @timestamp.to_unix == 0
flags = flags | FLAG_TYPE unless @type.empty?
flags = flags | FLAG_USER_ID unless @user_id.empty?
flags = flags | FLAG_APP_ID unless @app_id.empty?
Expand All @@ -191,7 +191,7 @@ module AMQP::Protocol
io.write_shortstr(@reply_to) unless @reply_to.empty?
io.write_shortstr(@expiration) unless @expiration.empty?
io.write_shortstr(@message_id) unless @message_id.empty?
io.write_timestamp(@timestamp) unless @timestamp.epoch == 0
io.write_timestamp(@timestamp) unless @timestamp.to_unix == 0
io.write_shortstr(@type) unless @type.empty?
io.write_shortstr(@user_id) unless @user_id.empty?
io.write_shortstr(@app_id) unless @app_id.empty?
Expand Down Expand Up @@ -607,7 +607,7 @@ module AMQP::Protocol
end

def write_timestamp(v : Time)
write(v.epoch.to_i64)
write(v.to_unix.to_i64)
end

protected def write_field(field)
Expand Down Expand Up @@ -682,9 +682,7 @@ module AMQP::Protocol
def read_timestamp
tv_sec = read_int64
return nil unless tv_sec
spec = LibC::Timespec.new
spec.tv_sec = tv_sec
Time.new(spec)
Time.unix tv_sec
end

def flush
Expand Down
6 changes: 3 additions & 3 deletions src/amqp/timed_channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Timed
private def sleep
interval = Time.now - @start_time
interval = @interval - interval
Fiber.sleep interval.total_seconds
sleep interval.total_seconds
end

private def receive_impl
Expand Down Expand Up @@ -52,7 +52,7 @@ module Timed
end

@queue.shift.tap do
Scheduler.enqueue @senders
Crystal::Scheduler.enqueue @senders
@senders.clear
end
end
Expand All @@ -64,7 +64,7 @@ module Timed
private def sleep(start_time, interval)
cur_interval = Time.now - start_time
interval = interval - cur_interval
Fiber.sleep interval.total_seconds
sleep interval.total_seconds
end
end
end