# \_decrementPreload and preload

**URL:** <https://discourse.processing.org/t/decrementpreload-and-preload/24618>\
**Category:** Development\
**Created:** [October 15, 2020, 11:36am UTC](https://discourse.processing.org/t/decrementpreload-and-preload/24618 "2020-10-15T11:36:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![caterpillar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/caterpillar/32/10857_2.png) [@caterpillar](https://discourse.processing.org/u/caterpillar)\
**Post date:** [October 15, 2020, 11:36am UTC](https://discourse.processing.org/t/decrementpreload-and-preload/24618/1 "2020-10-15T11:36:56Z")

</div>

I read [libraries tutorial](https://github.com/processing/p5.js/blob/main/contributor_docs/creating_libraries.md) and have a question about [Example of async function for callback and preload()](https://github.com/processing/p5.js/blob/main/contributor_docs/creating_libraries.md#example-of-async-function-for-callback-and-preload). I followed its code and wrote an example.

```auto
p5.prototype.loadXXX = function(callback) {
    const ret = {};
    
    setTimeout(() => {
        const data = {
            x: 1,
            y: 2
        };

        for (let prop in data) {
            ret[prop] = data[prop];
        }

        if (typeof callback == 'function') {
            callback(ret); // do the callback.
        }        

    }, 1000);

    return ret;
};
p5.prototype.registerPreloadMethod('loadXXX', p5.prototype);  

```

When calling `loadXXX` in `preload`, the canvas only show “Loading…”. I looked into those `loadXXX` function in the p5.js source, they all call `self._decrementPreload()`. I tried to rewrite my code.

```auto
p5.prototype.loadXXX = function(callback) {
    const ret = {};
    const self = this;
    
    setTimeout(() => {
        const data = {
            x: 1,
            y: 2
        };
        console.log('Timeout');
        for (let prop in data) {
            ret[prop] = data[prop];
        }

        if (typeof callback == 'function') {
            callback(ret); // do the callback.
        }        
        self._decrementPreload();

    }, 1000);

    return ret;
};
p5.prototype.registerPreloadMethod('loadXXX', p5.prototype);  

```

It works. I use p5.js 1.1.9. Is `self._decrementPreload()` an official way to do that? Does the doc require an update?
