Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grullo90 committed Feb 9, 2017
1 parent 6f9c749 commit 4a3e70e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015, Expand JS
Copyright (c) 2017, expand.js
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
36 changes: 23 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright (c) 2015 The expand.js authors. All rights reserved.
* Copyright (c) 2017 The expand.js authors. All rights reserved.
* This code may only be used under the BSD style license found at https://expandjs.github.io/LICENSE.txt
* The complete set of authors may be found at https://expandjs.github.io/AUTHORS.txt
* The complete set of contributors may be found at https://expandjs.github.io/CONTRIBUTORS.txt
Expand Down Expand Up @@ -65,30 +65,40 @@ module.exports = global.XPScheduler = new XP.Class('XPScheduler', {
// Listening
this.on('poll', handler);

// Invoking
// Handling
handler();
},

/**
* Adds a scheduled task.
*
* @method schedule
* @param {string} id
* @param {Date} date
* @param {Function} handler
* @param {string} [id]
* @param {Function} [handler]
* @returns {string}
*/
schedule(id, date, handler) {
schedule: {
callback: true,
value(date, id, handler) {

// Asserting
XP.assertArgument(XP.isString(id, true), 1, 'string');
XP.assertArgument(XP.isDate(date), 2, 'Date');
XP.assertArgument(XP.isFunction(handler), 3, 'Function');
// Asserting
XP.assertArgument(XP.isDate(date), 1, 'Date');
XP.assertArgument(XP.isVoid(id) || XP.isString(id, true), 2, 'string');
XP.assertArgument(XP.isFunction(handler), 3, 'Function');

// Unscheduling
if (this.scheduled[id]) { this.unschedule(id); }
// Preparing
if (!id) { id = XP.uuid(); }

// Setting
this.scheduled[id] = setTimeout(() => { delete this.scheduled[id]; handler(); }, date - Date.now());
// Unscheduling
if (this.scheduled[id]) { this.unschedule(id); }

// Setting
this.scheduled[id] = setTimeout(() => { delete this.scheduled[id]; handler(); }, date - Date.now());

// Returning
return id;
}
},

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/task.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright (c) 2015 The expand.js authors. All rights reserved.
* Copyright (c) 2017 The expand.js authors. All rights reserved.
* This code may only be used under the BSD style license found at https://expandjs.github.io/LICENSE.txt
* The complete set of authors may be found at https://expandjs.github.io/AUTHORS.txt
* The complete set of contributors may be found at https://expandjs.github.io/CONTRIBUTORS.txt
Expand Down

0 comments on commit 4a3e70e

Please sign in to comment.