example-solution

an anonymous user · March 20, 2023
async function sampleHandler(context) {
    const name = context.request.body.name;
    (async () => {
        await new Promise(resolve => setTimeout(resolve, 1000));
        console.log(name)
    })();
    context.response.code = 200
}

// A sample context object
const sampleContext = {
    request: {
        body: {
            name: 'Alice'
        }
    },
    response: {}
}
sampleHandler(sampleContext)

// Mutating the context object by modifying the request body
sampleContext.request.body.name = 'Bob'
sampleHandler(sampleContext)
Output
(Run the program to view its output)

Comments

Please sign up or log in to contribute to the discussion.