# async

Async Scheduler

### Firma

`const async: any;`

## Descripción

Planifica tareas de la misma forma que usando `setTimeout(task, duration)`.

El Planificador `async` planifica tareas asíncronamente, colocándolas en la cola del bucle de eventos de JavaScript. Se utiliza para retrasar tareas en el tiempo o para planificar tareas que se repitan en intervalos.

Si únicamente se quiere postergar la tarea, es decir, ejecutarla justo después de que finalice la ejecución actual síncrona de código (comportamiento comúnmente logrado mediante `setTimeout(tareaPostergada, 0)`), el Planificador [asap.](https://github.com/puntotech/rxjs-docu/blob/master/api/schedulers/asap/README.md)

## Ejemplos

### Ejemplos de la documentación oficial

Usar el Planificador async para retrasar una tarea

```javascript
import { asyncScheduler } from "rxjs";

const task = () => console.log("¡Funciona!");

asyncScheduler.schedule(task, 2000);

// Salida tras 2 segundos:
// "¡Funciona"
```

Usar el Planificador async para repetir una tarea en intervalos

```javascript
import { asyncScheduler } from "rxjs";

function task(state) {
  console.log(state);
  this.schedule(state + 1, 1000); // `this` referencia a la Action que se esté ejecutando en el momento,
  // que se replanifica con un nuevo estado y delay
}

asyncScheduler.schedule(task, 3000, 0);

/* Salida:
   0 tras 3s
   1 tras 4s
   2 tras 5s
   3 tras 6s
*/
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.rxjs.es/api/schedulers/async.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
