Code Monkey home page Code Monkey logo

Comments (3)

knowlsie avatar knowlsie commented on June 12, 2024

Reviewing this yesterday, I think that this is fine, and may even solve another issue. Here's a quick explanation of how Lambda works. It has event, context and callback objects. In the current version of the SDK, when it's done it calls context.succeed() (or similar.) In our RequestResponse model, this sends off a response. It then closes off the event loop and stops any async actions going on. However, because context.callbackWaitsForEmptyEventLoop === true, the lambda function does then run whatever the callback is. In our case it's undefined.

However, if context.callbackWaitsForEmptyEventLoop === false, it treats callback in pretty much the same way as context.succeed(). The nice part about this for us is that you can more easily edit and rewrite callback, and in testing you can make it do what you want; you can't do this with context.succeed(). More specifically, lambda-local automatically sets the context object, but it lets you edit the callback function.

Currently, the SDK always calls context.succeed(), and usually doesn't have a callback defined. However, PRs from me and other people will very likely change this, so it uses just callback instead of context.succeed().

Anyway, what does this mean for my testing? Well currently what my testing does it it runs the SDK code, which calls context.succeed(), and then a callback (defined by me) happens. This callback is where it confirms that the response we sent off was good. However, in the new version, the SDK itself will directly call the callback. I was concerned this might cause breaks, but it will actually be a much neater way to do it, as it means I'm directly editing the function that usually sends the response to Alexa. This will mean our tests no longer unintentionally log every single response, and I can customise the checks quite a bit better.

I'm also mildly hopeful (though it's unlikely) that this might fix #14. We'll see.

from alexa-room-finder.

knowlsie avatar knowlsie commented on June 12, 2024

Note that the above is theoretical, I plan to test it more extensively today.

from alexa-room-finder.

knowlsie avatar knowlsie commented on June 12, 2024

Having done some further research, it turns out that lambda-local actually just uses context.done as its callback, which then calls callback itself, if it's present. This means that pretty much no change occurs with this new change...

from alexa-room-finder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.