question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async filters not working since 29 Apr

See original GitHub issue

Just today I updated nunjucks in one of my apps. In particular, I was using Async filters, but they have stopped working completely, failing to output anything in place.

env.addFilter('test', function(obj, callback) {
    setTimeout(function() {
        callback(null, 'FOO');
    }, 1000);
}, true);

Strangely, the following does work (but this is besides the point):

env.addFilter('test', function(obj, callback) {
    callback(null, 'FOO');
}, true);

I was able to pinpoint the issue to this commit:

https://github.com/mozilla/nunjucks/commit/9e160e8d13bda3830e5799f75ed02ccb53550fdd

Whereas the following commit is still fine:

https://github.com/mozilla/nunjucks/commit/eadeb67deaf1f805ef34f953391e52503bc09273

I noticed that there are no tests to validate async filter behavior, which probably explains why it went unnoticed for so long … @jlongster care to take a look, please? Thanks!

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ArmorDarkscommented, Mar 9, 2018

Well, tested this out. It works. You need to ensure, that you’re using async renderer:

const nunjucks = require('nunjucks')

const env = nunjucks.configure()

env.addFilter('timout', ({ message, delay }, done) => {
  setTimeout(() => {
    console.log(message)
    done(null, message)
  }, delay)
}, true)

// it should use `(error, result)` callback, otherwise it will work in sync mode
env.render('source/templates/index.nj', {}, (error, result) => {
  console.log(error)
  console.log(result)
})
0reactions
callumlockecommented, Mar 28, 2017

Any progress on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Async Action Filter not working. ASP.NET Core Web Api
Show activity on this post. To disable the default model state handling, you need to add the below setting in Program.cs. builder.Services.
Read more >
Support for async filters for Liquid · Issue #831 · 11ty/eleventy
I did reinstate our Liquid test for async filters in 1.0 and it's working fine! It does not work in the old version...
Read more >
Asynchronous action filters in ASP.NET Web API - StrathWeb
It is rather to common to use filters in Web API to perform common tasks around your actions in an AOP (aspect oriented...
Read more >
[Update: Dec. 22] YouTube bugs/issues & pending ...
Here we are tracking all the bugs and problems found on YouTube and their status as ... Update 29 (February 15) ... Update...
Read more >
Deeply Understanding JavaScript Async and Await with ...
It is important to note the async functions work on top of promises. They are not a fundamentally different concept.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found