mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Removed Async[websocket/http] due to excessive require times and reliablity issues on Windows
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user