Code Monkey home page Code Monkey logo

postpone's Introduction

Postpone v0.5.5

Tool to manage a queue of tasks for browser-based apps and games.

Purpose

Execute specified tasks, even those that had to be run when the browser window remained closed.

Work in progress

  • Tests!
  • Manage OS notifications.
  • Improve the cross-device support of storage.

API

postpone.queue / postpone.q

Stores all the tasks with its execution date.

{
    'Wed Sep 26 2012 17:00:00 GMT-0300 (ART)': 'function () { ... }',
    'Fri Jan 04 2013 13:00:00 GMT-0300 (ART)': 'function () { ... }'
}

postpone.set()

Associates a task with the corresponding date string.

postpone.set(on, callback[, repeatAfter]);
  • on

    • A number representing the delay in minutes from "now" to use as key on the queue map. Also, it can be a valid date string.
  • callback

    • Method to be saved into the queue map to execute via its date string.
  • repeatAfter (optional)

    • A number that determines when to execute a clone of the current task. Expressed in minutes.

Example: Task to be executed in half an hour.

postpone.set(30, function () { ... });

Example: Task to be executed on September 26th.

postpone.set('2012/09/26 17:15', function () { ... });

Example: Execute each hour starting on May 3rd at 10pm.

postpone.set('Thu May 03 2012 22:00:00 GMT-0300 (ART)', function () { ... }, 60);

postpone.check()

Executes all the past tasks by comparing the dates into the queue with today's date and time.

Example: Initialize the check cicle (each minute)

setInterval(postpone.check, 60000);

postpone.clear()

Resets the queue.

Change log

v0.5.5

  • Fixed bug: Two equal dates only saves the last defined. Use the seconds of the date as an unique index on set(). It allows to grab 60 tasks per minute (0-59).
  • Fixed bug: clear() only resets the queue and not the q.

v0.5.4

  • Fixed bug: The name callback used to refer to an internal executable method when a task is saved with set(), was confused with the parameter sent as callback.

v0.5.3

  • Fixed bug: The delay of the new task created with the repeatAfter parameter, was a string. It wasn't recursive.
  • Keep the tasks unsorted but now check() analizes all the date strings of the queue.
  • When set() is executed, round seconds of the task date to get a normalized date.

v0.5.2

  • Fixed bug: Now the saved tasks are sorted because check() only verifies one task at a time (the first one).

v0.5.1

  • Use the repeatAfter parameter to get recursivity, instead to calculate the next date from execution.
  • Create the q alias for the queue property to fastest access when debugging.
  • Beautify the code of the callback function (as a string).
  • Use spaces instead tabs to indentate, and get a full validation at JSLint.

v0.5

  • Fixed bug: Tasks were not saved into the queue, because the native methods JSON.stringify() and JSON.parse() did not support "function" as JSON value. Now, it creates a custom method as string for each task and executes it by using a <script> tag (not eval() and not new Function()).
  • Add postpone.clear() to reset the queue.

v0.4

  • Use the on parameter of set() as a delay from "now" expressed in minutes.
  • Fixed bug: repeatAfter was always 1.

v0.3

  • Add the ability to create a recursive task by specifying a delay time.
  • Fixed bug: The date received as parameter of the executed task was the creation date of the task.

v0.2

  • Expose the queue as a public member.
  • Execute the tasks receiving the task date object as parameter.

v0.1

  • First commit

License

The MIT License (MIT)

Copyright (c) 2013 Leandro Linares

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

postpone's People

Contributors

lean8086 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.