Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

wait for SRE to be ready #22

Closed
pkra opened this issue Jul 17, 2018 · 4 comments
Closed

wait for SRE to be ready #22

pkra opened this issue Jul 17, 2018 · 4 comments
Labels

Comments

@pkra
Copy link
Owner

pkra commented Jul 17, 2018

We don't handle SRE's odd asynchronicity for SRE.ready.

Until Speech-Rule-Engine/speech-rule-engine#247 is fixed, we need a timeout/restart hack.

@pkra pkra added the bug label Jul 17, 2018
@pkra
Copy link
Owner Author

pkra commented Jul 17, 2018

here's one example

let restart = function() {
  if (!sre.engineReady()) {
    setTimeout(restart, 200);
    return;
  }
  main()
};

@pkra
Copy link
Owner Author

pkra commented Jul 18, 2018

Thanks to the amazing @zorkow, it seems mode: "sync" is sufficient, cf. Speech-Rule-Engine/speech-rule-engine#247 (comment)

@pkra
Copy link
Owner Author

pkra commented Jul 19, 2018

Hm... Seems like mode: "sync" is not sufficient after all.

The following will fail the first test -- but if you switch the order, it's fine (presumably because MathJax takes a longer time).

var tape = require('tape');
const mj = require('mathjax-node').typeset;
const postprocessor = require('../lib/main.js').postprocessor;
const preprocessor = require('../lib/main.js').preprocessor;

tape('Wait for sre.engineReady()', function(t) {
  t.plan(2);

  const input1 = {math: '(', format: "TeX", mmlNode: true};
  preprocessor(input1, function(output){
    console.log(output.math)
    t.ok(output.math.includes('left-parenthesis'), 'Preprocessor enrichment ok');
  });

  const input2 = {math: '(', format: "TeX", mml: true, mmlNode: true};

  mj(input, function(result, input){
    postprocessor({speakText: true}, result, input2, function(result){
      t.equal(result.speakText, 'left-parenthesis', 'Postprocessor ok');
    })
  });
});

@pkra
Copy link
Owner Author

pkra commented Jul 19, 2018

Thank you @zorkow for pushing out a fix in SRE v2.2.3-beta.0. I'll prep a proper patch.

@pkra pkra closed this as completed in 6cbdd9f Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant