🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

ztimer

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ztimer - rubygems Package Compare versions

Comparing version
0.4.0
to
0.4.1
+6
-7
lib/ztimer.rb

@@ -1,5 +0,1 @@

require 'set'
require 'hitimes'
require 'lounger'
require "ztimer/version"

@@ -13,3 +9,2 @@ require "ztimer/slot"

@watcher = Ztimer::Watcher.new(){|slot| execute(slot) }
@metric = Hitimes::Metric.new("Notifier")
@workers_lock = Mutex.new

@@ -24,3 +19,3 @@ @queue = Queue.new

def after(milliseconds, &callback)
enqueued_at = @metric.utc_microseconds
enqueued_at = utc_microseconds
expires_at = enqueued_at + milliseconds * 1000

@@ -70,3 +65,3 @@ slot = Slot.new(enqueued_at, expires_at, -1, &callback)

while !@queue.empty? && @queue.pop(true) do
slot.executed_at = @metric.utc_microseconds
slot.executed_at = utc_microseconds
slot.callback.call(slot) unless slot.callback.nil?

@@ -86,3 +81,7 @@ end

end
def utc_microseconds
return Time.now.to_f * 1_000_000
end
end
end
module Ztimer
VERSION = "0.4.0"
VERSION = "0.4.1"
end

@@ -7,7 +7,5 @@

@thread = nil
@idler = Lounger.new
@slots = Ztimer::SortedStore.new
@callback = callback
@lock = Mutex.new
@metric = Hitimes::Metric.new("Notifier")
@mutex = Mutex.new

@@ -33,3 +31,4 @@ end

if @thread
@idler.signal && @thread.run
@thread.wakeup
@thread.run
else

@@ -45,11 +44,15 @@ start

loop do
delay = get_delay
if delay.nil?
@idler.wait
next
end
begin
delay = get_delay
if delay.nil?
Thread.stop
next
end
select(nil, nil, nil, delay / 1_000_000.to_f) if delay > 1 # 1 microsecond of cranularity
select(nil, nil, nil, delay / 1_000_000.to_f) if delay > 1 # 1 microsecond of cranularity
while get_first_expired do
while get_first_expired do
end
rescue => e
puts e.inspect + "\n" + e.backtrace.join("\n")
end

@@ -63,3 +66,3 @@ end

def get_delay
return @mutex.synchronize { @slots.empty? ? nil : @slots.first.expires_at - @metric.utc_microseconds }
return @mutex.synchronize { @slots.empty? ? nil : @slots.first.expires_at - utc_microseconds }
end

@@ -70,5 +73,5 @@

slot = @slots.first
if slot && (slot.expires_at < @metric.utc_microseconds)
if slot && (slot.expires_at < utc_microseconds)
@slots.shift
slot.started_at = @metric.utc_microseconds
slot.started_at = utc_microseconds
unless slot.canceled?

@@ -92,3 +95,7 @@ execute(slot)

end
def utc_microseconds
return Time.now.to_f * 1_000_000
end
end
end

@@ -25,4 +25,2 @@ # coding: utf-8

spec.add_development_dependency "rspec", "~> 3.0"
spec.add_dependency "hitimes", "~> 1.2"
spec.add_dependency "lounger", "~> 0.2"
end