# promisify

## PromiseOptions

| Name               | Type                          | Description                                |
| ------------------ | ----------------------------- | ------------------------------------------ |
| callbacks          | (() => void)\[] \| Promise\[] | List of callbacks                          |
| callAtOnce = false | boolean                       | _Picture below_                            |
| interval = 100     | number                        | \[callAtOnce: true] updates interval in ms |

![App without promisify, with promisify() and with promisify({ callAtOnce: true })](https://4291835564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm77hcDeqeOAYWWBuMMpM%2Fuploads%2FIF13VmzAX4S2z5j6jpPg%2FScreenshot%20from%202022-01-14%2000-25-58.png?alt=media\&token=5bb5286e-399c-41ab-bc81-1e6869bd6d44)

## promisify function

### promise(options)

```typescript
import { fs, promisify } from '@empathize/framework';

// Call one function async
promisify(async () => {
    const files = await fs.files('my_folder');
    
    console.log(files);
});

// Wait for promise result
promisify(new Promise((resolve) => {
    setTimeout(() => {
        resolve('Hello, World!');
    }, 3000);
})).then(console.log);

// Call several functions async
promisify({
    callbacks: [
        () => console.log(1),
        () => console.log(2),
        () => console.log(3)
    ]
});

// Call several functions async together
promisify({
    callbacks: [
        () => console.log(1),
        () => console.log(2),
        () => console.log(3)
    ],
    callAtOnce: true
});

// Sum several callbacks results
promisify({
    callbacks: [
        () => 1,
        () => 2,
        () => 3
    ]
}).then((results) => {
    // 1 + 2 + 3 = 6
    console.log(results[0] + results[1] + results[2]);
});
```
