https://github.com/zmmbreeze/onetask
Only one running task for each browser
https://github.com/zmmbreeze/onetask
Last synced: 12 months ago
JSON representation
Only one running task for each browser
- Host: GitHub
- URL: https://github.com/zmmbreeze/onetask
- Owner: zmmbreeze
- Created: 2012-08-15T10:30:53.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-08-31T14:15:04.000Z (almost 14 years ago)
- Last Synced: 2025-04-09T19:15:01.338Z (about 1 year ago)
- Language: JavaScript
- Homepage: http://zmmbreeze.github.com/OneTask/
- Size: 138 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
One task for each browser
===========================
OneTask is a simple javascript library to make sure a timing task only execute in one page for each browser.
Example
---------------
Check out the index.html
API
--------------
var t = new OneTask(
'Name',
function(syncReturn, n1, n2, n3) {
// only server page run this function(Task)
n1 === 1;
n2 === 2;
n3 === 3;
// syncReturn: return the result of task
// result will be serialize to json string
syncReturn({
'm':'11'
});
},
{
interval: 30000, // interval of task
serverTimeout: 1000, // timeout of server
params: [1,2,3] // task params
}
);
// cancel the task, and can't start again
t.cancel();
// start the task
t.start();
// temporarily stop the task
t.stop();
// regist callback,which runs after the task
// parameter of callback is the result of task
t.onCallBack(function(data) {
this === t;
data.m === 11;
});
// regist callback,which runs when the result change
// parameter of callback is the result of task
t.onChangeCallBack(function(data) {
this === t;
data.m === 11;
});
NOTE: if the result of task is null, it means task is not ready. It's not a right result, don't use it;
#Licentse
MIT. Be pleasure to fork and modify it.