### Setting Up a Node.js Project for TinyTick Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/1_getting_started.md These shell commands guide the user through creating a new directory, navigating into it, initializing a Node.js project with default settings, and installing the `tinytick` package as a dependency. ```Bash mkdir MyFirstTinyTickApp cd MyFirstTinyTickApp npm init -y npm install tinytick ``` -------------------------------- ### Installing TinyTick with NPM Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/article.html This command installs the TinyTick module into your project using the Node Package Manager (NPM), making it available for import in your bundled application. ```Shell npm install tinytick ``` -------------------------------- ### Installing TinyTick in a Node.js Application - Bash Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/index.html This snippet provides the necessary shell commands to initialize a new Node.js project and install TinyTick as a dependency using npm, preparing the environment for development. ```Bash mkdir MyFirstTinyTickApp cd MyFirstTinyTickApp npm init -y npm install tinytick ``` -------------------------------- ### Setting Up Node.js Project for TinyTick Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/article.html These shell commands create a new directory for a Node.js application, initialize a `package.json` file, and install the `tinytick` module as a dependency, preparing the project for TinyTick integration. ```Shell mkdir MyFirstTinyTickApp cd MyFirstTinyTickApp npm init -y npm install tinytick ``` -------------------------------- ### Installing TinyTick with NPM Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/1_getting_started.md This command installs the `tinytick` module into your project using the Node Package Manager (NPM). It's the first step to integrate TinyTick into a bundled JavaScript application. ```Shell npm install tinytick ``` -------------------------------- ### Installing TinyTick Module with NPM - Bash Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/index.html This command installs the TinyTick module into your project using the Node Package Manager (NPM). It is the standard way to add TinyTick as a dependency in a bundled application. ```Bash npm install tinytick ``` -------------------------------- ### Starting TinyTick Manager with Chained Task Registration (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/5_advanced_usage/3_starting_and_stopping.md Illustrates a fluent API pattern for initializing the TinyTick Manager, registering multiple tasks (`hello` and `ping`), and immediately starting it. This approach streamlines setup and activation of the task processing engine. ```js const manager = createManager() .setTask('hello', async () => console.log('Hello!')) .setTask('ping', async (url) => fetch(url)) .start(); ``` -------------------------------- ### Initializing TinyTick Manager in JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/example-use-cases/paginated-and-nested-data/article.html This snippet demonstrates the initial setup of the TinyTick manager. It imports the `createManager` function, instantiates a new manager, and then starts it, preparing the system for task registration and scheduling. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Installing TinyTick via npm Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/releases/index.html This command installs the TinyTick library into your project using npm, the Node.js package manager. It is the first step to getting started with TinyTick. ```Shell npm install tinytick ``` -------------------------------- ### Running the TinyTick Node.js Application - Bash Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/index.html This command shows how to execute the `index.mjs` module script using Node.js, initiating the TinyTick application and its scheduled tasks. ```Bash node index.mjs ``` -------------------------------- ### Fluent Initialization and Starting of TinyTick Manager (TypeScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/advanced-usage/starting-and-stopping/article.html Illustrates a common fluent pattern for initializing the TinyTick Manager, registering multiple tasks, and immediately starting it. This allows for a concise setup where tasks are ready to run as soon as the manager is created. ```TypeScript const manager = createManager() .setTask('hello', async () => console.log('Hello!')) .setTask('ping', async (url) => fetch(url)) .start(); ``` -------------------------------- ### Initializing TinyTick Manager in a Bundled App - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/index.html This snippet demonstrates how to import the `createManager` function from the `tinytick` module, instantiate a new `Manager` object, and start its internal processing loop. This is the foundational step before defining and scheduling tasks. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Full Example of useStartCallback Hook in React Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/ui-react/functions/manager-hooks/usestartcallback/article.html This comprehensive example demonstrates how to integrate the useStartCallback hook within a React component. It illustrates the setup with createManager and Provider, and how the callback returned by useStartCallback can be used to programmatically start the Manager instance, triggered by a user interaction like a click, and update the UI based on the Manager's status. ```JavaScript import React from 'react'; import {createRoot} from 'react-dom/client'; import {createManager} from 'tinytick'; import {Provider, useStartCallback, useStatus} from 'tinytick/ui-react'; const Pane = () => { const handleClick = useStartCallback(); return ( Manager status: {useStatus()} ); }; const App = ({manager}) => ( ); const app = document.createElement('div'); const manager = createManager(); createRoot(app).render(); const span = app.querySelector('span'); console.log(span.innerHTML); // -> 'Manager status: 0' // User clicks the element: // -> span MouseEvent('click', {bubbles: true}) console.log(span.innerHTML); // -> 'Manager status: 1' ``` -------------------------------- ### Implementing a Basic TinyTick Manager - Node.js Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/index.html This JavaScript code demonstrates how to import and use the TinyTick manager to define an asynchronous task, schedule multiple runs of that task with different arguments, and manage the manager's lifecycle by starting and stopping it. It illustrates task execution and the importance of calling `stop()` for a clean process exit. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); manager.setTask('hello', async (noun) => console.log(`

Hello ${noun}!

`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); manager.stop(); ``` -------------------------------- ### Initializing and Starting TinyTick Manager with Tasks (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/advanced-usage/starting-and-stopping/index.html This example illustrates a fluent API pattern for initializing the TinyTick `Manager`. It creates a manager, registers two asynchronous tasks ('hello' and 'ping'), and then immediately starts the manager, allowing it to begin processing scheduled tasks. ```JavaScript const manager = createManager() .setTask('hello', async () => console.log('Hello!')) .setTask('ping', async (url) => fetch(url)) .start(); ``` -------------------------------- ### Installing TinyTick via npm (Shell) Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/7_releases.md This command demonstrates how to install the TinyTick library using npm, the Node.js package manager. It's the quickest way to get started with TinyTick in a JavaScript or TypeScript project. This command adds the `tinytick` package to your project's dependencies. ```sh npm install tinytick ``` -------------------------------- ### Initializing TinyTick Manager in a Bundled App Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/1_getting_started.md This JavaScript snippet imports the `createManager` function from the `tinytick` module, instantiates a new manager object, and starts its internal tick sequence, preparing it for task registration and scheduling. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Starting TinyTick Manager and Scheduling Tasks - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/lifecycle/start/index.html This example demonstrates how to initialize a TinyTick `Manager`, register a task, schedule a task run, and then start the manager. It illustrates that tasks do not run immediately upon scheduling but rather after the `start` method is called and the next `tickInterval` passes, showing the state before and after starting. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('ping', async () => await fetch('https://example.org')); manager.scheduleTaskRun('ping'); console.log(manager.getRunningTaskRunIds().length); // -> 0 manager.start(); // ... wait 100ms (the Manager tickInterval) for task run to start console.log(manager.getRunningTaskRunIds().length); // -> 1 ``` -------------------------------- ### Creating and Starting a TinyTick Manager (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/functions/creation/createmanager/article.html This example illustrates how to create a `Manager` object and immediately start it. Starting the manager is crucial for scheduled tasks to begin execution as intended. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Creating and Starting tinytick Manager (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example illustrates the typical workflow of creating a `tinytick` manager instance and immediately starting it using `manager.start()`. This ensures that any scheduled tasks within the manager begin execution without delay. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Registering and Scheduling Tasks with TinyTick Manager Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/1_getting_started.md This JavaScript code demonstrates how to register an asynchronous task named 'hello' with the TinyTick manager and then schedule multiple runs of this task with different arguments and delays. The task logs a greeting to the console. ```JavaScript manager.setTask('hello', async (noun) => console.log(`Hello ${noun}!`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); // ... wait 550ms to be sure the first task run has been executed // -> 'Hello world!' // ... wait 550ms to be sure the second task run has been executed // -> 'Hello universe!' ``` -------------------------------- ### Initializing TinyTick Manager in Bundled App Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/article.html This JavaScript snippet imports the `createManager` function from the `tinytick` module, instantiates a new Manager object, and starts its internal tick sequence, preparing it to handle scheduled tasks. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Registering and Scheduling Tasks with TinyTick Manager Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/article.html This code demonstrates how to register a named asynchronous task with the TinyTick Manager and then schedule multiple runs of that task with different arguments and delays. The task logs a greeting to the console. ```JavaScript manager.setTask('hello', async (noun) => console.log(`Hello ${noun}!`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); ``` -------------------------------- ### Running TinyTick Node.js Application Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/article.html This command executes the `index.mjs` module script using Node.js, initiating the TinyTick application and its scheduled tasks within the Node.js runtime environment. ```Shell node index.mjs ``` -------------------------------- ### Creating and Immediately Starting a Manager (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/functions/creation/createmanager/index.html This example illustrates the common pattern of creating a `Manager` instance and immediately calling its `start()` method. Starting the manager is crucial for scheduled tasks to begin execution promptly after creation. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Starting TinyTick Manager and Scheduling a Task (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/lifecycle/start/article.html This example demonstrates how to initialize a `TinyTick Manager`, register a task, schedule its execution, and then start the manager. It highlights that tasks do not run immediately upon `start()` call but after the next `tickInterval` passes. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('ping', async () => await fetch('https://example.org')); manager.scheduleTaskRun('ping'); console.log(manager.getRunningTaskRunIds().length); // -> 0 manager.start(); // ... wait 100ms (the Manager tickInterval) for task run to start console.log(manager.getRunningTaskRunIds().length); // -> 1 ``` -------------------------------- ### Executing a TinyTick Node.js Module Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/1_getting_started.md This command executes the `index.mjs` file using Node.js, running the TinyTick application defined within it. It's the final step to see the scheduled tasks execute in a Node environment. ```Bash node index.mjs ``` -------------------------------- ### Defining and Scheduling Tasks with TinyTick Manager - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/index.html This code illustrates how to define a task named 'hello' using `manager.setTask`, which takes an asynchronous function as its handler. It then schedules two runs of this task with different arguments and delays using `manager.scheduleTaskRun`, demonstrating basic task execution and parameter passing. ```JavaScript manager.setTask('hello', async (noun) => console.log(`Hello ${noun}!`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); // ... wait 550ms to be sure the first task run has been executed // -> 'Hello world!' // ... wait 550ms to be sure the second task run has been executed // -> 'Hello universe!' ``` -------------------------------- ### Implementing TinyTick in a Node.js Module Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/article.html This JavaScript code for `index.mjs` demonstrates how to use TinyTick in a Node.js application. It imports `createManager`, initializes and starts the manager, defines a task to log HTML to the console, schedules runs, and then stops the manager to allow the process to exit. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); manager.setTask('hello', async (noun) => console.log(`

Hello ${noun}!

`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); manager.stop(); ``` -------------------------------- ### Running TinyTick in a Node.js Application Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/1_getting_started.md This JavaScript module demonstrates how to use TinyTick in a standalone Node.js application. It imports `createManager`, starts the manager, defines a task to log output to the console, schedules task runs, and then stops the manager to allow the process to exit cleanly. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); manager.setTask('hello', async (noun) => console.log(`

Hello ${noun}!

`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); manager.stop(); ``` -------------------------------- ### Initializing TinyTick Manager in JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/6_example_use_cases/1_paginated_and_nested_data.md This snippet demonstrates the initial setup of the TinyTick manager. It imports the `createManager` function, instantiates a new manager, and then starts it, preparing the system to handle scheduled tasks. This is a prerequisite for defining and running any tasks. ```js import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Initializing TinyTick Manager in JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/advanced-usage/retries-and-backoff/article.html This snippet demonstrates the initial setup of a TinyTick `Manager`. It imports `createManager` from the 'tinytick' library, instantiates a manager, and then starts it, which is a prerequisite for defining and scheduling tasks. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Creating a Minimum Viable TinyTick Application Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/releases/index.html This example illustrates the fundamental steps to create and use a TinyTick manager. It demonstrates how to initialize a manager, define a task using setTask, schedule multiple runs of that task with scheduleTaskRun, and start the manager to execute the scheduled tasks. ```TypeScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('hello', async (noun) => console.log(`Hello ${noun}!`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); manager.start(); // ... wait 550ms to be sure the first task run has been executed // -> 'Hello world!' // ... wait 550ms to be sure the second task run has been executed // -> 'Hello universe!' ``` -------------------------------- ### Integrating TinyTick in a Browser with UMD Script - HTML Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/index.html This HTML snippet shows how to include TinyTick directly in a web page using a minified UMD script from a CDN. It initializes the manager on page load, defines a task that writes to the document, and schedules two runs, demonstrating browser-based usage without a module bundler. ```HTML My First TinyTick App ``` -------------------------------- ### Integrating TinyTick in a Browser with UMD Script Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/getting-started/article.html This HTML snippet shows how to include TinyTick in a web page using a UMD script from a CDN. It initializes the Manager, defines a task to write content to the document, schedules task runs, and then stops the manager. ```HTML My First TinyTick App ``` -------------------------------- ### Scheduling and Stopping Tasks with Manager in TinyTick (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example demonstrates how to register and schedule tasks using `tinytick`'s `createManager`. It shows how to schedule a task to run immediately and another after a delay, and then how to start and forcefully stop the manager, observing the state of scheduled and running tasks at different stages. It highlights the effect of the `force` flag during stopping. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('ping', async () => await fetch('https://example.org')); manager.scheduleTaskRun('ping'); manager.scheduleTaskRun('ping', '', 200); // In two tick intervals' time console.log(manager.getScheduledTaskRunIds().length); // -> 2 console.log(manager.getRunningTaskRunIds().length); // -> 0 manager.start(); // ... wait 100ms (the Manager tickInterval) for task run to start console.log(manager.getScheduledTaskRunIds().length); // -> 1 console.log(manager.getRunningTaskRunIds().length); // -> 1 manager.stop(true); // ... wait 100ms; the first task run will end but the second won't start console.log(manager.getScheduledTaskRunIds().length); // -> 1 console.log(manager.getRunningTaskRunIds().length); // -> 0 ``` -------------------------------- ### Creating tinytick Manager and Getting Config (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example demonstrates how to initialize a `tinytick` manager using `createManager()` and then retrieve its current configuration settings by calling `manager.getManagerConfig(true)`, which outputs the default configuration object. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); console.log(manager.getManagerConfig(true)); // -> {tickInterval: 100} ``` -------------------------------- ### Integrating TinyTick in a Browser with UMD Script Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/1_getting_started.md This HTML snippet shows how to include TinyTick directly in a web page using its minified UMD script from a CDN. It initializes the manager, registers a task that writes to the document, and schedules two runs, then stops the manager. ```HTML My First TinyTick App ``` -------------------------------- ### Using useStartCallback Hook to Start Manager in React Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example illustrates the `useStartCallback` hook, which provides a callback to start the `tinytick` Manager. The callback is triggered when the status `` element is clicked, demonstrating how to programmatically control the manager's lifecycle from a React component. ```JavaScript import React from 'react'; import {createRoot} from 'react-dom/client'; import {createManager} from 'tinytick'; import {Provider, useStartCallback, useStatus} from 'tinytick/ui-react'; const Pane = () => { const handleClick = useStartCallback(); return ( Manager status: {useStatus()} ); }; const App = ({manager}) => ( ); const app = document.createElement('div'); const manager = createManager(); createRoot(app).render(); const span = app.querySelector('span'); console.log(span.innerHTML); // -> 'Manager status: 0' // User clicks the element: // -> span MouseEvent('click', {bubbles: true}) console.log(span.innerHTML); // -> 'Manager status: 1' ``` -------------------------------- ### Example: Registering Manager Status Listener - tinytick (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example illustrates how to use `addStatusListener` to monitor the `Manager`'s status changes. It creates a manager, registers a listener to log status updates, starts and stops the manager to trigger status changes, and then removes the listener. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); const listenerId = manager.addStatusListener((manager, status) => { console.log(`Manager status changed to: ${status}`); }); manager.start(); // -> 'Manager status changed to: 1' manager.stop(); // -> 'Manager status changed to: 2' // ... wait 100ms for the final tick to stop the manager // -> 'Manager status changed to: 0' manager.delListener(listenerId); ``` -------------------------------- ### Retrieving Task Run Configuration - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/taskrun/gettaskrunconfig/article.html This example demonstrates how to use `getTaskRunConfig` to retrieve the configuration of a scheduled task run. It shows how to get both the explicitly set configuration and the full configuration including inherited defaults by passing `true` for the `withDefaults` parameter. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setCategory('network', {maxDuration: 5000}); manager.setTask( 'ping', async () => await fetch('https://example.org'), 'network', {maxRetries: 3}, ); const taskRunId = manager.scheduleTaskRun('ping', '', 0, {retryDelay: 10}); console.log(manager.getTaskRunConfig(taskRunId)); // -> {retryDelay: 10} console.log(manager.getTaskRunConfig(taskRunId, true)); // -> {maxDuration: 5000, maxRetries: 3, retryDelay: 10, repeatDelay: null} ``` -------------------------------- ### Initializing TinyTick Manager in Stopped State (TypeScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/advanced-usage/starting-and-stopping/article.html Demonstrates how to create a new TinyTick Manager instance, which is in a stopped state by default. It shows how to check the manager's status, confirming it's initially `0` (stopped), allowing for setup before task execution. ```TypeScript import {createManager} from 'tinytick'; const stoppedManager = createManager(); console.log(stoppedManager.getStatus()); // -> 0 /* stopped */ ``` -------------------------------- ### Initializing TinyTick Manager (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/5_advanced_usage/2_retries_and_backoff.md This snippet demonstrates how to initialize and start a TinyTick Manager instance. The `createManager` function is imported from the `tinytick` library, and the `start()` method is called to begin the manager's operation, enabling it to schedule and run tasks. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); ``` -------------------------------- ### Example Usage of addTaskRunRunningListener - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/listener/addtaskrunrunninglistener/index.html This JavaScript example demonstrates the setup of a TinyTick manager and the definition of a simple 'ping' task. While the `addTaskRunRunningListener` call itself is not shown, this snippet provides the necessary context for where such a listener would be registered to monitor the 'ping' task's run state changes. It initializes the manager and defines an asynchronous task. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager().start(); manager.setTask('ping', async () => await fetch('https://example.org')); ``` -------------------------------- ### Registering a Task with TinyTick Manager in JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/defining-tasks/index.html This example shows how to initialize a TinyTick `Manager` and register an asynchronous task. It imports `createManager`, starts the manager, and then uses `setTask` to associate the 'ping' task (which fetches from 'https://example.org') with a unique ID. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); manager.setTask('ping', async () => await fetch('https://example.org')); ``` -------------------------------- ### Starting TinyTick Manager and Scheduling Tasks (TypeScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This snippet demonstrates how to start the `Manager` using the `start()` method and observe its effect on scheduled tasks. It registers a task, schedules it, and then starts the manager, showing that the task begins running after the `tickInterval` passes. ```TypeScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('ping', async () => await fetch('https://example.org')); manager.scheduleTaskRun('ping'); console.log(manager.getRunningTaskRunIds().length); // -> 0 manager.start(); // ... wait 100ms (the Manager tickInterval) for task run to start console.log(manager.getRunningTaskRunIds().length); // -> 1 ``` -------------------------------- ### Initializing and Starting TinyTick Manager in JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/demos/scheduling/index.html This JavaScript code imports the `createManager` function from the 'tinytick' library. It then instantiates a new `Manager` object and immediately starts it, preparing the TinyTick system for task management and scheduling. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager().start(); ``` -------------------------------- ### Getting Task Run Information - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/taskrun/gettaskruninfo/article.html This example demonstrates how to use `getTaskRunInfo` to retrieve details about a scheduled task run. It shows the process of creating a manager, setting a task, scheduling a task run, and then accessing properties like `taskId`, `arg`, and `running` from the returned `TaskRunInfo` object. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('ping', async (url) => await fetch(url)); const taskRunId = manager.scheduleTaskRun('ping', 'https://example.org'); const info = manager.getTaskRunInfo(taskRunId); console.log(info.taskId); // -> 'ping' console.log(info.arg); // -> 'https://example.org' console.log(info.running); // -> false ``` -------------------------------- ### Starting TinyTick Manager with useStartCallback in React Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/ui-react/functions/manager-hooks/usestartcallback/index.html This comprehensive example illustrates the integration of `useStartCallback` within a React application. It demonstrates how to create a TinyTick `Manager`, provide it via a `Provider` component, and then use `useStartCallback` in a nested component to obtain a function that starts the manager when an element is clicked. The `useStatus` hook is also used to display the manager's current state, showing the transition from 0 to 1 upon activation. ```JavaScript import React from 'react'; import {createRoot} from 'react-dom/client'; import {createManager} from 'tinytick'; import {Provider, useStartCallback, useStatus} from 'tinytick/ui-react'; const Pane = () => { const handleClick = useStartCallback(); return ( Manager status: {useStatus()} ); }; const App = ({manager}) => ( ); const app = document.createElement('div'); const manager = createManager(); createRoot(app).render(); const span = app.querySelector('span'); console.log(span.innerHTML); // -> 'Manager status: 0' // User clicks the element: // -> span MouseEvent('click', {bubbles: true}) console.log(span.innerHTML); // -> 'Manager status: 1' ``` -------------------------------- ### Installing TinyTick Library - Shell Source: https://github.com/tinyplex/tinytick/blob/main/releases.md This command installs the TinyTick library using npm, the Node.js package manager. It is the first step to set up TinyTick in your project, making the core library and its modules available for use. ```Shell npm install tinytick ``` -------------------------------- ### Installing TinyTick via npm Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/releases/article.html This command installs the TinyTick library using npm, the Node.js package manager. It is the first step to setting up TinyTick in a JavaScript or TypeScript project, making the core library and its React bindings available for use. ```npm npm install tinytick ``` -------------------------------- ### Example of TinyTick Provider Component Usage in React Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example demonstrates how to use the `Provider` component from `tinytick/ui-react` to make a TinyTick `Manager` available throughout a React application. It initializes a manager, wraps the application with the `Provider`, and shows how child components can access the manager's status using `useManager`. ```JavaScript import React from 'react'; import {createRoot} from 'react-dom/client'; import {createManager} from 'tinytick'; import {Provider, useCreateManager, useManager} from 'tinytick/ui-react'; const App = () => { const manager = useCreateManager(() => createManager().start()); return ( ); }; const Pane = () => Status: {useManager().getStatus()}; const app = document.createElement('div'); const root = createRoot(app); root.render(); console.log(app.innerHTML); // -> 'Status: 1' ``` -------------------------------- ### Manager.start() Method Signature - TypeScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/lifecycle/start/index.html This snippet shows the signature of the `start` method, indicating it takes no arguments and returns a reference to the `Manager` instance itself. It signifies the method's role in initiating the internal ticking process. ```TypeScript start(): Manager ``` -------------------------------- ### Registering a Task with TinyTick Manager in JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/3_defining_tasks.md This example shows how to initialize a TinyTick `Manager` object and register an asynchronous task. It imports `createManager`, instantiates and starts the manager, then uses `manager.setTask()` to associate the 'ping' task (which fetches from `https://example.org`) with a unique ID, making it available for scheduling. ```js import {createManager} from 'tinytick'; const manager = createManager(); manager.start(); manager.setTask('ping', async () => await fetch('https://example.org')); ``` -------------------------------- ### Registering a Did Tick Listener with TinyTick Manager (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/listener/adddidticklistener/article.html This example demonstrates how to register a listener using `addDidTickListener` that logs a message every time the `Manager` ticks. It shows the setup, starting the manager, and then stopping it and removing the listener by its ID. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); const listenerId = manager.addDidTickListener(() => console.log('Manager did tick'), ); manager.start(); // ... wait 250ms, long enough for two ticks to occur // -> 'Manager did tick' // -> 'Manager did tick' manager.stop(); manager.delListener(listenerId); ``` -------------------------------- ### Initializing and Starting tinytick Manager (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/site/demos/01_scheduling.md This JavaScript snippet imports the `createManager` function from the 'tinytick' library. It then instantiates a new Manager object and immediately starts it, preparing it for task definition and scheduling. ```js import {createManager} from 'tinytick'; const manager = createManager().start(); ``` -------------------------------- ### Monitoring Running Task IDs with Listener in TinyTick (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example demonstrates how to use `addRunningTaskRunIdsListener` to monitor changes in the list of currently running task IDs. It shows how to register a task, schedule its execution, and observe the listener's output as the task starts and completes, reflecting the number of active tasks. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager().start(); manager.setTask('ping', async () => await fetch('https://example.org')); const listenerId = manager.addRunningTaskRunIdsListener((manager) => console.log(manager.getRunningTaskRunIds().length + ' running Ids'), ); manager.scheduleTaskRun('ping'); // ... wait 150ms for task to start // -> '1 running Ids' // ... wait 150ms again for task to complete // -> '0 running Ids' manager.delListener(listenerId); ``` -------------------------------- ### Getting Manager Status Text in TinyTick (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/functions/utility/getmanagerstatustext/index.html This example demonstrates how to use the `getManagerStatusText` function to retrieve and log the current status of a TinyTick `Manager` instance. It illustrates the status changing from 'stopped' to 'running' and then to 'stopping' as the manager's lifecycle methods (`start`, `stop`) are called. ```JavaScript import {createManager, getManagerStatusText} from 'tinytick'; const manager = createManager(); console.log(getManagerStatusText(manager.getStatus())); // -> 'stopped' manager.start(); console.log(getManagerStatusText(manager.getStatus())); // -> 'running' manager.stop(); console.log(getManagerStatusText(manager.getStatus())); // -> 'stopping' ``` -------------------------------- ### Manager start Method Signature Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/lifecycle/start/article.html Defines the signature for the `start` method of the `Manager` interface, indicating it takes no arguments and returns a reference to the `Manager` instance itself. ```TypeScript start(): Manager ``` -------------------------------- ### Example Usage of useManager Hook in React Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/ui-react/functions/manager-hooks/usemanager/article.html This comprehensive example demonstrates the integration of `useManager` within a React application. It illustrates how to initialize a `Manager` with `createManager`, wrap components with `Provider` to make the manager available, and then consume the manager in a nested `Pane` component using `useManager` to display its status. ```JavaScript import React from 'react'; import {createRoot} from 'react-dom/client'; import {createManager} from 'tinytick'; import {Provider, useManager} from 'tinytick/ui-react'; const Pane = () => { const manager = useManager(); return
Status: {manager ? manager.getStatus() : 'unknown'}
; }; const App = () => { const manager = createManager().start(); return ( ); }; const app = document.createElement('div'); const root = createRoot(app); root.render(); console.log(app.innerHTML); // -> '
Status: 1
' ``` -------------------------------- ### Creating a Minimum Viable TinyTick Application - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/releases.md This example illustrates a basic standalone TinyTick application. It demonstrates how to create a manager, define a task named 'hello' that logs a greeting, and then schedule two runs of this task with different arguments and delays. The `manager.start()` call initiates the task execution, showing how tasks are processed asynchronously. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('hello', async (noun) => console.log(`Hello ${noun}!`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); manager.start(); // ... wait 550ms to be sure the first task run has been executed // -> 'Hello world!' // ... wait 550ms to be sure the second task run has been executed // -> 'Hello universe!' ``` -------------------------------- ### Initializing and Starting TinyTick Manager in JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/index.html This snippet demonstrates how to import the `createManager` function from the 'tinytick' library and immediately initialize and start a new `Manager` instance. The `manager` object serves as the main entry point for interacting with the TinyTick API, enabling task registration and scheduling. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager().start(); ``` -------------------------------- ### Getting Manager Status in TinyTick (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/lifecycle/getstatus/index.html This example demonstrates how to retrieve the lifecycle status of a TinyTick `Manager` instance using the `getStatus()` method. It shows the status transitions (stopped, running, stopping) as the manager is created, started, and stopped, including a forced stop. The method returns a numeric value representing the `ManagerStatus` enumeration. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); console.log(manager.getStatus()); // -> 0 manager.start(); console.log(manager.getStatus()); // -> 1 manager.stop(); console.log(manager.getStatus()); // -> 2 manager.stop(true); // force stop console.log(manager.getStatus()); // -> 0 ``` -------------------------------- ### Getting Manager Configuration with and without Defaults - JavaScript Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This snippet demonstrates how to retrieve the `Manager`'s configuration using `getManagerConfig`. It shows the difference between getting the full configuration including defaults (when `withDefaults` is `true`) and getting only the explicitly set configuration (when `withDefaults` is `false` or omitted). When no custom configuration is set, the latter returns an empty object. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); console.log(manager.getManagerConfig(true)); // -> {tickInterval: 100} console.log(manager.getManagerConfig()); // -> {} ``` -------------------------------- ### Integrating TinyTick Manager with React Hooks Source: https://github.com/tinyplex/tinytick/blob/main/docs/guides/releases/article.html This example demonstrates how to integrate the TinyTick Manager with a React application using the tinytick/ui-react module. It shows the use of Provider to make the manager available, useCreateManager to instantiate it, useSetTask to register a task, and useScheduleTaskRunCallback to get a callback for scheduling a task run. This setup ensures consistent manager usage across components. ```JavaScript import { Provider, useCreateManager, useScheduleTaskRunCallback, useSetTask, } from 'tinytick/ui-react'; const App = () => ( ); const Panel = () => { useSetTask('ping', async () => await fetch('https://example.org')); return ; }; ``` -------------------------------- ### Getting Manager Configuration with and without Defaults in TinyTick (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/manager/getmanagerconfig/index.html This example demonstrates how to create a TinyTick `Manager` instance and retrieve its configuration using `getManagerConfig`. It shows the difference between getting the full configuration including defaults (`true` argument) and getting only the explicitly set configuration (no argument), which is empty if no custom configuration was provided. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); console.log(manager.getManagerConfig(true)); // -> {tickInterval: 100} console.log(manager.getManagerConfig()); // -> {} ``` -------------------------------- ### Example Usage of useTaskRunRunning Hook in React (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/ui-react/functions/task-run-hooks/usetaskrunrunning/article.html This comprehensive example demonstrates how to integrate the `useTaskRunRunning` hook within a React component. It sets up a TinyTick `Manager` and `Provider`, schedules a task, and reactively updates the UI based on the task's running status, showcasing the hook's dynamic behavior. ```JavaScript import React from 'react'; import {createRoot} from 'react-dom/client'; import {createManager} from 'tinytick'; import {Provider, useTaskRunRunning} from 'tinytick/ui-react'; const Pane = ({taskRunId}) => ( Task run running: {useTaskRunRunning(taskRunId) ? 'true' : 'false'} ); const App = ({manager, taskRunId}) => ( ); const manager = createManager(); manager.setTask('ping', async () => await fetch('https://example.org')); const app = document.createElement('div'); const root = createRoot(app); const taskRunId = manager.scheduleTaskRun('ping'); root.render(); console.log(app.innerHTML); // -> 'Task run running: false' manager.start(); // ... wait 100ms for task to start running console.log(app.innerHTML); // -> 'Task run running: true' // ... wait 100ms for task to complete console.log(app.innerHTML); // -> 'Task run running: false' ``` -------------------------------- ### Minimum Viable TinyTick Application (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/site/guides/7_releases.md This snippet illustrates a basic TinyTick application, demonstrating how to create a manager, define an asynchronous task, and schedule multiple runs of that task with different arguments and delays. It shows the core `createManager`, `setTask`, `scheduleTaskRun`, and `start` methods. The comments indicate the expected output and timing of task execution. ```js import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('hello', async (noun) => console.log(`Hello ${noun}!`)); manager.scheduleTaskRun('hello', 'world', 500); manager.scheduleTaskRun('hello', 'universe', 1000); manager.start(); // ... wait 550ms to be sure the first task run has been executed // -> 'Hello world!' // ... wait 550ms to be sure the second task run has been executed // -> 'Hello universe!' ``` -------------------------------- ### Using useRunningTaskRunIds Hook in React Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/ui-react/functions/task-run-hooks/userunningtaskrunids/index.html This example demonstrates how to use the `useRunningTaskRunIds` hook within a React component (`Pane`) to display the count of currently running task run IDs. It illustrates the hook's reactive nature, showing how the component re-renders to reflect changes in the `Manager`'s state as tasks are scheduled, start, and complete. The setup includes creating a TinyTick manager, defining a task, and rendering a React application with a `Provider`. ```JavaScript import React from 'react'; import {createRoot} from 'react-dom/client'; import {createManager} from 'tinytick'; import {Provider, useRunningTaskRunIds} from 'tinytick/ui-react'; const Pane = () => ( Running task run Ids: {useRunningTaskRunIds().length} ); const App = ({manager}) => ( ); const manager = createManager().start(); manager.setTask( 'takes200ms', async () => await new Promise((resolve) => setTimeout(resolve, 200)), ); const app = document.createElement('div'); const root = createRoot(app); root.render(); console.log(app.innerHTML); // -> 'Running task run Ids: 0' manager.scheduleTaskRun('takes200ms'); console.log(app.innerHTML); // -> 'Running task run Ids: 0' // ... wait 100ms for task run to start console.log(app.innerHTML); // -> 'Running task run Ids: 1' // ... wait 200ms for task run to stop console.log(app.innerHTML); // -> 'Running task run Ids: 0' ``` -------------------------------- ### Example: Registering a Did Tick Listener (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/tinytick/interfaces/manager/manager/methods/listener/adddidticklistener/index.html This example demonstrates the usage of `addDidTickListener` to register a function that executes after each tick of the TinyTick manager. It shows the full lifecycle from creating a manager, adding a listener, starting and stopping the manager, and finally removing the listener using its ID. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); const listenerId = manager.addDidTickListener(() => console.log('Manager did tick'), ); manager.start(); // ... wait 250ms, long enough for two ticks to occur // -> 'Manager did tick' // -> 'Manager did tick' manager.stop(); manager.delListener(listenerId); ``` -------------------------------- ### Scheduling a Basic Task in TinyTick (JavaScript) Source: https://github.com/tinyplex/tinytick/blob/main/docs/api/all.html This example demonstrates how to initialize a TinyTick manager, register a simple 'ping' task, and then schedule it to run using `scheduleTaskRun` without additional arguments or configurations. It also shows how to retrieve the number of scheduled tasks and the default run configuration. ```JavaScript import {createManager} from 'tinytick'; const manager = createManager(); manager.setTask('ping', async () => await fetch('https://example.org')); const taskRunId = manager.scheduleTaskRun('ping'); console.log(manager.getScheduledTaskRunIds().length); // -> 1 console.log(manager.getTaskRunConfig(taskRunId, true)); // -> {maxDuration: 1000, maxRetries: 0, retryDelay: 1000, repeatDelay: null} ```