Removed Async[websocket/http] due to excessive require times and reliablity issues on Windows

This commit is contained in:
2022-10-30 18:10:47 -05:00
parent 7359d73027
commit 340c083a43
12 changed files with 176 additions and 210 deletions

View File

@@ -9,13 +9,12 @@ class W3DHub
logger.info(LOG_TAG) { "Starting background job worker..." }
@@thread = Thread.current
@@alive = true
@@run = true
@@instance = self.new
Async do
@@instance.handle_jobs
end
@@instance.handle_jobs
end
def self.instance
@@ -30,10 +29,18 @@ class W3DHub
@@alive
end
def self.busy?
instance&.busy?
end
def self.shutdown!
@@run = false
end
def self.kill!
@@thread.kill
end
def self.job(job, callback, error_handler = nil)
@@instance.add_job(Job.new(job: job, callback: callback, error_handler: error_handler))
end
@@ -43,6 +50,7 @@ class W3DHub
end
def initialize
@busy = false
@jobs = []
end
@@ -50,12 +58,16 @@ class W3DHub
while BackgroundWorker.run?
job = @jobs.shift
@busy = true
begin
job&.do
rescue => error
job&.raise_error(error)
end
@busy = !@jobs.empty?
sleep 0.1
end
@@ -67,6 +79,10 @@ class W3DHub
@jobs << job
end
def busy?
@busy
end
class Job
def initialize(job:, callback:, error_handler: nil, deliver_to_queue: false)
@job = job