I'm trying to write the following code into a es2015 class syntax:
export function initialize(port) {
return new Promise((resolve, reject) => {
const application = express();
const server = application.listen(port, function listening(error) {
if (error) reject(error);
resolve(server);
});
});
}
const server = async initialize(port);
es2015:
class Server {
constructor(port) {
return new Promise((resolve, reject) => {
const application = express();
const server = application.listen(port, function listening(error) {
if (error) reject(error);
resolve(server);
});
});
}
}
const server = async new Server(port); // <-- not a good idea!
Apparently returning and a Promise
is not such a good idea when using the new
which should return an instant instance. Any ideas?