Use more reliable control flow for child safeTranslator objects#35
Open
AbeJellinek wants to merge 1 commit into
Open
Use more reliable control flow for child safeTranslator objects#35AbeJellinek wants to merge 1 commit into
safeTranslator objects#35AbeJellinek wants to merge 1 commit into
Conversation
adomasven
reviewed
Mar 25, 2024
| } | ||
| return returnValue; | ||
| }) | ||
| .finally(() => translate.decrementAsyncProcesses("safeTranslator#translate()")); |
Member
There was a problem hiding this comment.
Let's use try {} finally {} with an let returnValue = await translation.translate() instead of then.
Member
|
Can we have a testcase for this? It would be easier to follow the logic than the explanation above. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
itemDonehandler, andsafeTranslatorwraps 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 adonehandler 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 wheredonehandlers never got triggered at all. Apparentlydonehandlers 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.