scotttrinh/angular-localForage

Nested Promises do not work

midhunadarvin opened this issue · 3 comments

Hi,

I have the below code for updating a key using $localForage Service. The $localForage.setItem() promise doesn't get resolved. Since I am using it within the callback of a Promise.

A related issue is given here : 27

Any help would be greatly appreciated. Thanks.

function setCourses(data) {
         return $localForage.getItem('COURSES')
		.then(function(courses) {
			if(!courses) {
				courses = {};
			} else {
				courses = JSON.parse(courses);
			}
			courses = Object.assign(courses, data);
			courses = JSON.stringify(courses);
			console.log(courses);
			return $localForage.setItem('COURSES', courses);
		})
		.catch(function(error) {
			console.log(error);
			reject(error);	
		});
       });
}

👋 @midhunadarvin !

Thanks for reaching out. I've definitely had nested Promises in my code for years now, so I hope that I can help you figure out what's happening. For a little detail, localForage uses Promises also but we're wrapping those into the Angular digest loop, so it should trigger, but maybe you're hitting a strange case. I'll give it a look and get back to you ASAP with some ideas, or if I find an actual bug, maybe you can help me validate it?

Can you provide me with a few more details?

  • What browsers are you using to test this?
  • Is this failing when you manually test this in the browser, or in your tests?

@scotttrinh
Thank you for your reply. I'm really sorry for your trouble. It was not related with $localForage. The promise was not resolved in another part of my application. I am closing this issue.