Okay I followed how-to-return-the-response-from-an-asynchronous-call
No matter what I can't able to update variable tag.. How to update tag
function foo() {
// RETURN the promise
return fetch("stack-url").then(function(response){
return response.json(); // process it inside the `then`
});
}
self.addEventListener('push', function(event){
var title = 'Featured Message';
var body = 'StackOverFlow Question Got Featured Post';
var tag = 'this-is-dummy-tag';
foo().then(function(response){
console.log('this is then result ', response);
var tag = response.question_id;
return tag;
// access the value inside the `then`
})
event.waitUntil(
self.registration.showNotification(title, {
body:body,
tag:tag,
})
);
});