Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule: Tear down #266

Closed
UFOMelkor opened this issue Apr 11, 2017 · 3 comments

Comments

@UFOMelkor
Copy link

commented Apr 11, 2017

I try to connect textlint with the node-languagetool.
node-languagetool runs a service and then sends commands to this service which are executed asynchronously.
Thanks to #75 this is no problem. But the service started by node-languagetool is running until it is explicitly killed. Is there any way to execute this after all checks are done?

@azu

This comment has been minimized.

Copy link
Member

commented Apr 11, 2017

textlint doesn't provide after-all hook, but you can write following:

var lt = require('node-languagetool');
module.exports = (context) => {
  const {Syntax, getSource, RuleError, report} = context;
  const promiseQueue = [];
  return {
    [Syntax.Str](node) {   
      var text = getSource(node);    
      // add queue  
      promiseQueue.push(lt.check(text));
    },
    // call at the end
    // Syntax.Document <-> Syntax.Document:exit
    // https://github.com/textlint/textlint/blob/master/docs/rule.md
    [`${Syntax.Document}:exit`](node){
      // Note: textlint wait for `Promise.all` is resolved.
      return Promise.all(promiseQueue).then((...responses) => {
        responses.forEach(response => {
           // do somthing...
        });
      }).then(() => {
          // after-all
      });
    }
  }
}
@UFOMelkor

This comment has been minimized.

Copy link
Author

commented Apr 11, 2017

That works, thank you 👍

@UFOMelkor UFOMelkor closed this Apr 11, 2017

@azu azu added the Type: Question label Apr 11, 2017

@azu azu changed the title Tear down rule:Tear down Apr 11, 2017

@azu azu changed the title rule:Tear down Rule: Tear down Apr 11, 2017

@azu

This comment has been minimized.

Copy link
Member

commented Apr 11, 2017

We will add a documentation about this question.
#269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.