I have the a onMessage.addListener function like this:
chrome.runtime.onMessage.addListener(function (r, s, sendResponse) {
if (r.action == "read") {
readManga(request, function () {
sendResponse({});
}, true);
}
if (r.action == "write") {
readManga(request, function () {
sendResponse({});
}, true);
}
if (request.action == "update") {
$.each(request.list, function (index, val) {
resetManga(val, function () {}, false);
});
saveList();
refreshUpdate();
sendResponse({});
}
if (request.action == "release") {
releaseImplentationFromId(request.id, function (mirrorName) {
updateMirrors(function () {
sendResponse({
mirror : mirrorName
});
});
return true
});
}
}
(this is an excerpt, but it's working code and please ignore all the if's, I should have used case since long ago)
Each time I use the callback function sendResponse
(again, I need to rename it, but lets ignore that) as defined in the documentation is never used unless I have return true
after it's execution. Is this really necessary or I just found a dirty hack and I'm doing something wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…