webpack/examples/top-level-await/db-connection.js

17 lines
402 B
JavaScript
Raw Normal View History

const connectToDB = async url => {
await new Promise(r => setTimeout(r, 1000));
2019-05-23 15:18:06 +08:00
};
2019-05-23 15:18:06 +08:00
// This is a top-level-await
await connectToDB("my-sql://example.com");
export const dbCall = async data => {
2019-05-23 15:18:06 +08:00
// This is a normal await, because it's in an async function
await new Promise(r => setTimeout(r, 100));
return "fake data";
2019-05-23 15:18:06 +08:00
};
export const close = () => {
console.log("closes the DB connection");
};