587 posts
Location
Wrocław, Poland
Posted 17 June 2013 - 10:17 AM
Hi all, I've question:
We have main block of code with func() in it and some code after it. Is it possible to run code after calling func() in parallel with func(). I need parallel started from func() itself, not from main code, i.e.
local function func()
-- Some code here to start parallel and do function's stuff'
end
func()
print("Hi! I need this code run in parallel with func()!")
print("Is it possible?")
print("PS Parallel have to be started from func() - I'm making an API")
I hope you understood :P/>
8543 posts
Posted 17 June 2013 - 10:29 AM
That's not how parallel works. You establish two or more functions to run in the parallel call. You'll have to put the code you want to run while the parallel call runs into it as well.
587 posts
Location
Wrocław, Poland
Posted 17 June 2013 - 10:54 AM
I know, that's why I ask :P/>
Can you make it in coroutines tho?
300th post! Woo!
194 posts
Location
Spain
Posted 17 June 2013 - 11:13 AM
I made an API that allows you to run functions in the background, just what you need. It still at early development with more APIs so I didn't released it yet. However you can use it at your own risk:
https://github.com/d.../Apis/multitaskPlease read the USAGE comment before trying to use it.
After loading it as it says in usage, you can just do
multitask.addProcess("name", func)
And it will run it in the background. You can stop the function when you want with
multitask.terminateProcess("name")
I hope you find this useful.
587 posts
Location
Wrocław, Poland
Posted 17 June 2013 - 11:52 AM
It's not what I need…
194 posts
Location
Spain
Posted 17 June 2013 - 01:58 PM
It's not what I need…
Then I didn't understand your question…
8543 posts
Posted 17 June 2013 - 02:00 PM
I know, that's why I ask :P/>
Can you make it in coroutines tho?
Parallel uses coroutines. What are you actually trying to do? Give us more details about what the actual problem you're trying to solve is. What's all this for?
587 posts
Location
Wrocław, Poland
Posted 17 June 2013 - 03:53 PM
I made Button API that I want to improve. It takes button object to handle and draw button, callback to be called in parallel with button handling and callback to be called when button is pressed. I want to remove first callback and run code which is (in file) after calling function to create button in parallel with click handling. It's a bit hard to explain :)/>
194 posts
Location
Spain
Posted 17 June 2013 - 05:05 PM
I solved that problem in my API with a table and an event handler.
When you create a button, instead of creating his own thread to handle clicking, add it to a table. When a click event is fired, you just need to loop through the table and check for each button in the screen if it was pressed. The event handler is a function called on the background when the API is loaded.