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

Support async itemDone on child translator #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AbeJellinek
Copy link
Member

@zoe-translates pointed out that you can't set an async itemDone handler on a child translator, like

let translate = Zotero.loadTranslator('web');
translate.setTranslator('...');
translate.setHandler('itemDone', (obj, item) => {
	let abstractNote = (await requestJSON('https://...')).description;
	item.abstractNote = abstractNote;
	item.complete();
}
await translate.translate();

Instead, that code will cause translation to fail (no items returned) when it awaits the HTTP request.

It looks like we already support async handlers (in most cases, at least!). We just weren't awaiting handlers set on child safeTranslators, nor were we incrementing/decrementing async processes in order to wait for the itemDone handler to complete when the child translator doesn't await Item#complete(). This PR fixes those two issues. Client translation tests are passing.

@zoe-translates
Copy link

Thank you - this will make writing translator code much easier. Right now quite a lot of "itemDone" handlers make use of the blocking doGet() function that we want to get rid of, but we can't without this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants