0

I need one or more Napa workers to do something in a setInterval loop. I am not entirely sure if that is officially supported yet (I have seen a Git Publish stating that the functionality was added).

I have tried many things, the following code is only the latest thing I tried:


    import * as napa from "napajs"
    const zone1 = napa.zone.create('zone1', { workers: 4 });

    zone1.execute(function ()
    {
        const timers = require('napajs/lib/core/timers');

        timers.setInterval(function ()
        {
            console.log("asd");

        }, 100);
    }).then(function (res)
    {
        console.log(res);

    }).catch(function (err)
    {
        console.log(err);

    });

I expect the loop to work, in which case the server doesn't stop printing "asd". Or at least throw an error. Instead, it seems the code works without any errors and ends prematurely before the first console.log can even execute.

Thanks in advance!

Houssein K
  • 105
  • 8

1 Answers1

1

Your process exit before console.log("asd")

You can add process.stdin.resume() to the end of the file to prevent the process from exiting.

import * as napa from "napajs"
const zone1 = napa.zone.create('zone1', { workers: 4 });

zone1.execute(function ()
{
    const timers = require('napajs/lib/core/timers');

    timers.setInterval(function ()
    {
        console.log("asd");

    }, 100);
}).then(function (res)
{
    console.log(res);

}).catch(function (err)
{
    console.log(err);

});

process.stdin.resume()

Check doing a cleanup action just before node.js exits for more information.

banyudu
  • 1,046
  • 9
  • 19