util_task_task.js

/**
 * @module Task
 * @fileoverview Contains Task class.
 */

/**
 * Abstract task for use in TaskManager. Do not use without extending.
 * @class
 * @abstract
 */
class Task {
    /**
     * Create a new abstract task.
     * @constructor
     */
    constructor() {
        this._done = false;
    }


    // Getters

    /**
     * Check if the task is complete and can be removed.
     * @returns {boolean} Whether the task has completed
     */
    isDone() {
        return this._done;
    }


    // Initialization

    /**
     * Initialize the task.
     */
    init() {}


    // Updating

    /**
     * Update the task.
     * @param {number} elapsed Time since last update cycle in seconds
     */
    update(elapsed) {}

    /**
     * Set the task's status to done so it will be removed.
     */
    stop() {
        this._done = true;
    }
}

export default Task;