Async downloading and parsing


#1

Hello,
my app on its start downloads and parses several xml files from different sources.
Downloading and parsing is combined in single observable

		let myObservable = Observable.create(observer => {
			
			this.http.get(url).map(res => res.text()).subscribe(
			(data)=> {
				var k, arr = [], channel_title, channelImage,
				parser = new xml2js.Parser(
				{
					trim: true,
					explicitArray: true,
				});
				parser.parseString(data, function (err, result)
				{

finishing with passing data to subscriber in observer.next

observer.next( {title: channel_title, url: url, items: arr, active: false, image: channelImage, queue: queue, err: null } );

Not sure about that but it seems to me that parser.parseString is called syncronously, as an app hangs time by time when downloading and parsing.

I’m using some queue when next observable is started after previous has been completed, and I get periodical app hangs, that seems to be related to xml parsing steps.

What I’m not sure - does the code in subscribe part executes syncronously? I.e. on a main UI thread?

If yes - how could I change all this workflow into one single observer, that does all async and provide data to a main thread when both downloading and parsing is done?

I found something seems to be relevant about Observable.fromPromise, can it help?

Thank you,

p.s. tried to provide “async: false” to parser constructor, behaviour has been changed, data downloads ok, however experience problems displaying data, UI just does not update until I update it manually, that could be probably because UI update request is done on another thread.