Use more reliable control flow for child safeTranslator
objects
#35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make sure that
Item#complete()
is set to the parent translator's version of that method before returning fromtranslate()
.This was already the case in practice, but for a weird reason: there's no way to get a usable (i.e. un-completed) item object from a child translator without overriding the default
itemDone
handler, andsafeTranslator
wraps your handler in some code that overwritescomplete()
. So even adding an empty handler -translation.setHandler('itemDone', (_obj, _item) => {})
- invisibly causes the item objects passed to it to be modified so that a later(await translation.translate())[0].complete()
works. That's really odd and hard to debug. Now we're explicit about modifying the item object in all cases where it's returned to the parent.translate.decrementAsyncProcesses("safeTranslator#translate()")
was being called from adone
handler that was only added once, the first timetranslate()
got called. That caused translation never to complete if the parent translator called a child translator'stranslate()
multiple times (not sure if anyone actually does that), but more critically, also in cases wheredone
handlers never got triggered at all. Apparentlydone
handlers never get triggered when the translator ID passed tosetTranslator()
doesn't resolve (deleted translator, typo, ...), so translation was hanging in that case. Now we decrement infinally()
, which is much more reliable.