Skip to content

Instantly share code, notes, and snippets.

@keremtiryaki
Created May 20, 2020 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keremtiryaki/ba2f9a55f147f6f3a3f7e5417bddc734 to your computer and use it in GitHub Desktop.
Save keremtiryaki/ba2f9a55f147f6f3a3f7e5417bddc734 to your computer and use it in GitHub Desktop.
// don't wait for a response
const https = require('https');
let requestAndForget = async (host, path, message) => {
message = JSON.stringify(message);
var options = {
hostname: host,
method: 'POST',
path: path,
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(message),
},
};
await new Promise((resolve, reject) => {
let req = https.request(options);
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
reject(e);
});
req.write(message);
req.end(() => {
console.log("NOW it's not λ1's problem anymore.");
resolve();
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment