Skip to content

Commit

Permalink
✨ AsyncTask
Browse files Browse the repository at this point in the history
with *AsyncTask* now you can perform asynchronous calls with less effort
  • Loading branch information
TheEEs committed Apr 27, 2021
1 parent bba4245 commit e755019
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/components/async_task.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "./*"

class AsyncTask < JSCObject
enum States
Pending
Finished
Failed
end

@state = States::Pending
@param : JSC::JSValue = WebExtension.undefined.to_jsc
getter state
getter param

def initialize(callback : JSCFunction)
super()
self["callback"] = callback
end

def resolve(param)
@param = param.to_jsc
@state = States::Finished
end

def reject(param)
@param = param.to_jsc
@state = States::Failed
end

def callback : JSCFunction
self["callback"].as(JSCFunction)
end
end

0 comments on commit e755019

Please sign in to comment.