It is currently Fri May 26, 2017 7:27 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Synchronous file operation?
Unread postPosted: Wed Oct 19, 2016 2:08 am 
Offline

Joined: Sat May 14, 2011 7:43 am
Posts: 357
Location: South Africa, UK & US (Florida)
I didn't know whether to put this in 'questions' or 'enhancements', as perhaps it is already possible? But I can't find out how.
Let us suppose that a BASIC! program is running in a tight (graphics?) loop and encounters a condition that requires a file operation (perhaps a graburl?).
Currently the program is suspended until the file operation completes or times-out.
It would be very valuable if, instead, the program could resume its loop whilst testing a 'flag' which would be set when the file operation either completed or timed-out.
I know this is asking a lot from a single-threading interpreter, but it WOULD be nice!
Any ideas or prospect?
Peter


Report this post
Top
 Profile  
 
 Post subject: Re: Synchronous file operation?
Unread postPosted: Wed Oct 19, 2016 2:57 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
Hi Peter,

I suppose you want to continue refreshing the UI while downloading something in the background ?
This would require multi-threading, yes, so not natively supported by BASIC!

...at last not graphic mode, but in fact you can do it in HTML mode !
(I do it in the Compiler, when dexifying for example).

You can launch a javascript code to do some UI operations for a certain time (or until you send an 'end' message to the WebView) and in the meantime run your BASIC! commands...

If your whole program is in graphic mode, maybe you can just switch to HTML only the time of doing this multi-thread operation, then resume the GR mode ?

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Synchronous file operation?
Unread postPosted: Wed May 03, 2017 7:12 pm 
Offline

Joined: Mon Aug 08, 2016 12:36 pm
Posts: 6
mougino wrote:
This would require multi-threading, yes, so not natively supported by BASIC!


Would you consider putting multi-threading as a feature in the future?


Report this post
Top
 Profile  
 
 Post subject: Re: Synchronous file operation?
Unread postPosted: Thu May 04, 2017 9:27 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 327
Hi Peter,

file handling in the background is on Android normally a task for a Service.

A roughly Solution 1 for BASIC!'s main version:
* Create a second Service App for file handling
* Insert a Timer in your second Service App
* If the Timer sends an interrupt look in a file todo.txt
* If first line command=Load
* && second line URL=http..........
* && third line start
* THEN load the file
* If finished change the third line to finished
* If an error occurred change the third line to error
* EXIT the Service App

* Insert a Timer in your main App
* Create a file todo.txt with useful commands if you want to load a file
* Start with APP.Start the second APP
* On timer interrupt you should bring your main APP with maybe console.tofront on top again
* Kill the Timer
* Create a new Timer
* On timer interrupt you check the third line of todo.txt for "finished" or "error"
* Do what you want with the downloaded file and clear todo.txt
* Return to your main loop

Note: If you EXIT the Service APP its process could be killed but could be also in background.


A roughly Solution 2 for my test version:
* Create a second Service App for file handling
* Insert Broadcast filters
* Send a Broadcast to the main App "I am ready"
* On reseiving a command broadcast from the main APP load the wanted file.
* If finished send a Broadcast to the main App "finished"
* If an error occurred send a Broadcast to the main App "error"
* Wait for the next command broadcast
* If received "exit" then EXIT

* Insert Broadcast filters in your main App
* Start with APP.Start or App.SAR the second SERVICE APP
* On broadcast interrupt receiving "I am ready" you should bring your main APP with maybe console.tofront on top again
* Return to your main loop
* On broadcast interrupt receiving "error" maybe start again
* On broadcast interrupt receiving "finished" do what you want with the downloaded file
* Return to your main loop

Note: If you EXIT the Service APP its process could be killed but could be also in background.
See also:
https://github.com/RFO-BASIC/Basic/files/876323/OliBasicXVII.zip
http://rfobasic.freeforums.org/post36303.html?hilit=#p36303

Happy coding
Gregor


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred