# Using Pool

PoolManager is a pool for repeatable or delayed task

Let's imagine you want a loop to send to your backend that your user is online.&#x20;

For that we'll choose a component who's always loaded (let's take the NavBar)

```javascript
import AbstractComponent from "../../Plasma/Abstract/AbstractComponent";
import Session from "../../Plasma/Security/Session";

export default class NavbarComponent extends AbstractComponent {


    constructor() {
        super();

        this.setData({
            userName: Session.getUserName()
        })
        this.script()

    }

    render() {
        let template = this.getVue('include/navbar.twig')
        return this.getTemplate(template, this.data)
    }

    script() {

    }
}


```

First let's create our repeat method we'll call it imOnline (add it after script() {}

```javascript
imOnline(controller){
    //do your stuff
    if (PLASMA.poolManager.isTaskExist("imOnlineLoop")) {
        PLASMA.poolManager.execute("imOnlineLoop")
    }
}
```

As you see your method need to have one param : the controller.&#x20;

inside your method you'll have to call poolManager for two things :&#x20;

first check if the task exist, then execute them. (this gonna create the loop)&#x20;

### Define the task

on your script() method we'll define our task&#x20;

```javascript
if (!PLASMA.poolManager.isTaskExist("imOnlineLoop")) {
    PLASMA.poolManager.createTask("imOnlineLoop", this.imOnline, delay, this)
} else {
    PLASMA.poolManager.startTask("imOnlineLoop")
}
```

first we check if the task exist, if not we'll create it. if exist we'll start it (changing route make loop to be trigger) this is why you need to be sure the loop exist or not.

Each loop has unique name , method to call, delay, component&#x20;

The delay is in millis

### Unload a task :

Remember the method unload on the controller ? This method is called when you change From one controller to an other. Simply add these lines inside the unload method :&#x20;

```javascript
PLASMA.poolManager.stopTask("imOnlineLoop")
```

Of course you can also call this method from everywhere. Method need the task name.&#x20;
