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 rendering #35

Open
graingert opened this issue May 24, 2019 · 7 comments
Open

support async rendering #35

graingert opened this issue May 24, 2019 · 7 comments

Comments

@graingert
Copy link

https://mozilla.github.io/nunjucks/api.html#asynchronous-support

@ForbesLindesay
Copy link
Member

Looks good. Would you be up for creating a pull request for this?

@graingert
Copy link
Author

graingert commented May 24, 2019 via email

@ForbesLindesay
Copy link
Member

You could implement the renderAsync method: https://github.com/jstransformers/jstransformer#renderasync

@graingert
Copy link
Author

That's not allowed as a result of compile

@ForbesLindesay
Copy link
Member

No, I mean you can have a single function renderAsync that does both compile and render in one go. e.g. https://github.com/jstransformers/jstransformer-rollup only implements renderFileAsync.

@graingert
Copy link
Author

graingert commented May 25, 2019 via email

@gijswijs
Copy link

I think I have a solution for this, but it snowballed into having to make another PR for test-jstranformer. jstransformers/test-jstransformer#50

I implemented compileAsync. This is enough (I think) to offer the asynchronous support that nunjucks offers. At least it works in my project. But it doesn't pass the tests. This is (again, I think) because the test is wrong. The test assumes that template.fn(locals) returns a string. Hence the test
fails when that functions returns a promise, because template.fn(locals).trim() returns an error. By
wrapping it in a Promise.resolve() both the situations where template.fn(locals) returns a string or a Promise are covered. This is also how the jstranformer library works, so the tests now better mimick the behavior of the actual library. The test-jstransformer PR also adds a switch for async testing.

If that PR gets accepted, we can update to the latest test-jstransformer release in this repo, and then this PR #42 should pass testing.

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

No branches or pull requests

3 participants