Thanks Aparajita,
I'm back to working with A4D next week so will have a look at this.
Sounds like a great feature...
Regards, Michael.
On 24 Oct 2009, at 21:47, Aparajita Fishman wrote:
Hi,
I had the occasion to need periodic tasks for a project I'm working
on, and came up with a generic a4d.tasks library. Here is the
current design:
create(inMethodToExecute; inPeriodInMinutes {; inData {; inLimit}}) -
> longint
- inMethodToExecute must be a globally accessible Active4D library
method with the following signature:
method "myTask"($inId; $inAction; $ioData)
- inId is the task id
- inAction is "init", "exec", or "deinit"
- ioData is the data that was passed into 'create task'
- you may call 'delete($inId)' within this method to cause the task
to be deleted on the next run
- inPeriodInMinutes is how long between calls, >= 1. No guarantee
the task will be run that often, it is actually the minimum number
of minutes between calls, since the queue is only checked every 10
seconds
- inData if passed and non-zero must be a *global* collection, it
will be cleared with 'deep clear collection' when the task is deleted
- inLimit if passed is the number of times you want the task to be
executed, after which it will be removed, < 0 means unlimited
delete(inId)
- remove the task and deep clear its data
- if called from a currently running task, marks it for deletion on
the next run
dump
- Dumps the task list to the A4D console
I would like any comments or suggestions before I release it as part
of the Active4D standard libs. The task runner will be a 4D method
running in a separate process that calls a4d.tasks.execute every 10
seconds.
Typically in one of your libraries, you would do something like this:
method "__load__"
self{"mytask"} := a4d.tasks.create("mylib.mytaskHandler"; 1)
end method
method "__unload__"
ad4.tasks.delete(self{"mytask"})
end method
method "mytaskHandler"($id; $action; $data)
case of
:($action = "init")
// do some init
:($action = "exec")
// run my task
:($action = "deinit")
// cleanup
end case
end method
Kind regards,
Aparajita
www.aparajitaworld.com
"If you dare to fail, you are bound to succeed."
- Sri Chinmoy | www.srichinmoy.org
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/