JSScheduleAPI: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Module Schedule is based on module Promise, which landed about 5 months ago. === Object |Schedule| === Object |Schedule| offers a mechanism for: * launching tasks asynchronousl...") |
No edit summary |
||
| Line 1: | Line 1: | ||
=== Object <tt>Schedule</tt> === | |||
Object <tt>Schedule</tt> offers a mechanism for: | |||
* launching tasks asynchronously; | * launching tasks asynchronously; | ||
* setting up synchronization barriers between asynchronous tasks. | * setting up synchronization barriers between asynchronous tasks. | ||
To schedule the asynchronous execution of a function | To schedule the asynchronous execution of a function <tt>f</tt>: | ||
var my_schedule = Schedule.queue(f); | var my_schedule = Schedule.queue(f); | ||
| Line 13: | Line 11: | ||
var my_schedule = Schedule.on("foo"); | var my_schedule = Schedule.on("foo"); | ||
Both methods return objects of class | Both methods return objects of class <tt>Schedule</tt>. | ||
=== Constructor | === Constructor <tt>Schedule</tt> === | ||
This class offers mechanisms for: | This class offers mechanisms for: | ||
| Line 22: | Line 20: | ||
* signaling success/error in a schedule (inherited from Promise). | * signaling success/error in a schedule (inherited from Promise). | ||
To schedule asynchronous execution of a function | To schedule asynchronous execution of a function <tt>g</tt> in case of successful execution: | ||
var my_schedule2 = my_schedule.queue | var my_schedule2 = my_schedule.queue<tt>g</tt>; // |g| receives result | ||
To execute a function | To execute a function <tt>g</tt> in case of error: | ||
var my_schedule2 = my_schedule.trap(g); // |g| receives error | var my_schedule2 = my_schedule.trap(g); // |g| receives error | ||
To execute a function | To execute a function <tt>g</tt> regardless of success or error: | ||
var my_schedule2 = my_schedule.always(g);// |g| receives nothing | var my_schedule2 = my_schedule.always(g);// |g| receives nothing | ||
| Line 43: | Line 41: | ||
=== Further options === | === Further options === | ||
To delay execution by | To delay execution by 100 milliseconds: | ||
var my_schedule = Schedule.queue(f, {delay: 100}); | var my_schedule = Schedule.queue(f, {delay: 100}); | ||
or | or | ||
var my_schedule2 = my_schedule.queue(f, {delay: 100}); | var my_schedule2 = my_schedule.queue(f, {delay: 100}); | ||
Revision as of 15:53, 22 March 2012
Object Schedule
Object Schedule offers a mechanism for:
- launching tasks asynchronously;
- setting up synchronization barriers between asynchronous tasks.
To schedule the asynchronous execution of a function f:
var my_schedule = Schedule.queue(f);
To synchronize upon some global barrier "foo":
var my_schedule = Schedule.on("foo");
Both methods return objects of class Schedule.
Constructor Schedule
This class offers mechanisms for:
- waiting for successful execution of an asynchronous task;
- trapping errors in asynchronous tasks (inherited from Promise):
- signaling success/error in a schedule (inherited from Promise).
To schedule asynchronous execution of a function g in case of successful execution:
var my_schedule2 = my_schedule.queueg; // |g| receives result
To execute a function g in case of error:
var my_schedule2 = my_schedule.trap(g); // |g| receives error
To execute a function g regardless of success or error:
var my_schedule2 = my_schedule.always(g);// |g| receives nothing
To create an empty Schedule, for synchronization purposes:
var my_schedule2 = new Schedule();
To signal a success:
var my_schedule2.resolve(result);
To signal an error:
var my_schedule2.reject(error)
Further options
To delay execution by 100 milliseconds:
var my_schedule = Schedule.queue(f, {delay: 100});
or
var my_schedule2 = my_schedule.queue(f, {delay: 100});