bluefire
Version:
Lightweight tcp framework
73 lines (59 loc) • 1.79 kB
text/coffeescript
###
Main class that represents registered task. This class is using TaskAction
to provide context for more Tasks with same type.
Gelidus
0.0.3a
###
module.exports = class Task
constructor: (action, options = { }) ->
this.action = action
this.options = options
if not .repeat?
.repeat = false
else
if not .repeatTimes?
.repeatTimes = 0
if not .timeout?
.timeout = 0
###
Method that will perform current task by creating TaskAction with the
given context and options (may be changed).
context [Object] Any object with which should task manipulate
options [Object] Options to be passed into the TaskAction
action [TaskAction] Currently created TaskAction
###
perform: (context, options = ) =>
action = new TaskAction(context, options, )
return action
###
This class represents each task being made witing the given context.
Options are derived from the main Task class.
Gelidus
0.0.3a
###
class TaskAction
constructor: (, , ) ->
if .repeat is true
= 1
= setInterval(, .timeout)
else
= setTimeout(, .timeout)
###
Stops the current TaskAction, any currently executing callbacks
won't be stopped, but no more will be executed.
###
stop: () =>
if not ?
return
if .repeat is true
clearInterval()
else
clearTimeout()
perform: () =>
()
if .repeat is true
if .repeatTimes > or .repeatTimes is -1 # repeat infinitely when -1
++
else
()
return