I have a code that searches for some data in memory storage and if not found searches that data on server and caches it in memory. How can I return an object as a Promise so that the caller can just invoke a "done" on it?
The code looks like that:
if (foundInLocalStorage)
{
// This part I cannot make to work, caller does not have its 'done' fired
var defered = $.Deferred();
defered.resolve();
defered.promise(dataFound);
}
else
{
return $.ajax
(
{
url: someUrl,
dataType: 'json',
data: { id: 101 }
}
)
.done
(
//That part is fine
......
);
}