markushedvall / node-plantuml

A Node.js module and CLI for running PlantUML
MIT License
195 stars 53 forks source link

Console blocks when using this module in commanderjs console application #12

Closed marcofranssen closed 8 years ago

marcofranssen commented 8 years ago

I'm using following code in a commandjs app blocks my console.

plantuml.useNailgun();

plantuml.generate(file.contents.toString(), { format: 'png' }, (err, data) => console.log(data));

I did some more research and it happens as soon I add any of following lines of code.

plantuml.useNailgun();

or

plantuml.generate(file.contents.toString(), { format: 'png' }, (err, data) => console.log(data));

or the combination of both.

This causes me to do a ctrl+c in order to get my console back. How can I solve this?

markushedvall commented 8 years ago

Using nailgun will start a child process running a Nailgun server. Your process will run until the nailgun child process exits. There are two ways to close it, one to use process.exit(0) which will also close the Nailgun server. The other way is to use the server object returned by useNailgun():

const nailgunServer = plantuml.useNailgun(() => {
  plantuml.generate(file.contents.toString(), { format: 'png' }, (err, data) => {
    console.log(data)
    nailgunServer.shutdown()
  })
})

However, it's unnecessary to use Nailgun if you are only generating one time in your applications lifetime.

Your other issue is that using generate by itself is also blocking your application. I could succefully run the same code, printing the data before exiting. So I'm assuming you also never got any log printout with the generated data?

What is the string you get from file.contents.toString()?

marcofranssen commented 8 years ago

Awesome.... I was using it in a loop. I resolved my issue. Thanks.