RxJS Observable fromPromise and interactive loop in CLI app

Viewed 485

I'm building a simple command line tool using node.js.

In the past, I was using a Promise approach with something like this

function listenCommand(){
    inquirer.prompt([{
        type:'input',
        name:'value',
        message:"Enter commande :"
    }]).then(function (command) {
        processCmd(command);
    });
}

function processCmd(){
   ...
   listenCommand()
}

That would create my main loop to enter commands. When a command is executed the app will ask for a next one.

I'm now trying to transpose that into a RxJS approach with something like.

function listenCommand(){
    let listener = Rx.Observable.fromPromise(inquirer.prompt([{
        type:'input',
        name:'value',
        message:"Enter commande :"
    }]));

    listener.subscribe(function (command) {
        processCmd(command);
    });
}

function processCmd(){
   ...
   listenCommand()
}

It works but that doesn't sounds good.

What is the right way for doing this prompt loop with RxJS? Or is RxJS not suited for that kind of job and should I stick to the Promise approach instead?

1 Answers
Related