import { assert } from "../../../assert.js";
import Task from "../Task.js";
import { TaskSignal } from "../TaskSignal.js";

/**
 * Single-shot task. Executes supplied function once and resolved so success
 * @param {function} action
 * @param {string} [name]
 * @return {Task}
 */
export function actionTask(action, name = "unnamed") {
    assert.isString(name, 'name');

    return new Task({
        name,
        cycleFunction() {
            action();

            return TaskSignal.EndSuccess;
        }
    });
}
