This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
The Blue daNoob's profile picture

Concurrency without Parallel?

Started by The Blue daNoob, 25 November 2012 - 05:33 PM
The Blue daNoob #1
Posted 25 November 2012 - 06:33 PM
I've looked all over for this, but couldn't find it.

I'm trying to create a program that runs in the background on startup.

However, I don't want to call parallel.waitForAll(<myfunction>,function() shell.run("shell") end).

Is there a way I can start it in the background, then just have the computer continue functioning normally?

I want to be able to do this so that if the computer has some other startup code, that gets run.
Dlcruz129 #2
Posted 25 November 2012 - 06:53 PM
You can't do multi-tasking without parallel. Why don't you like the parallel API? Its so useful.
The Blue daNoob #3
Posted 25 November 2012 - 06:57 PM
I'm all for the parallel API.

But then I have to do

parallel.waitForAll(<function>,function() shell.run('shell') end)

If the computer is set to do something else tho, that would make the user screan ?Hey! Something's up!"
Although, I could just put all the rest of the code in a function…
Dlcruz129 #4
Posted 25 November 2012 - 07:00 PM
Use waitForAny, not waitForAll.
KaoS #5
Posted 25 November 2012 - 07:05 PM
I'm all for the parallel API. But then I have to do
 parallel.waitForAll(,function() shell.run('shell') end) 
If the computer is set to do something else tho, that would make the user screan ?Hey! Something's up!" Although, I could just put all the rest of the code in a function…

once you have called shell the PC will behave as if it just restarted, just clear the screen first and it will look fine? I'm guessing you are trying to make a virus 'cos you don't want the owner to see that it is running
ChunLing #6
Posted 26 November 2012 - 07:32 AM
You're just saying that because of the "make the user screan ?Hey! Something's up!"
Lyqyd #7
Posted 26 November 2012 - 08:11 AM
You can't do multi-tasking without parallel.

This is completely untrue.

once you have called shell the PC will behave as if it just restarted, just clear the screen first and it will look fine? I'm guessing you are trying to make a virus 'cos you don't want the owner to see that it is running

The problem with this approach is that you won't execute anything in the startup file past the call to parallel.waitForWhatever, and you won't see the results of anything executed before that call in the newly-spawned shell.

OP, you might check out the top-level coroutine post in the Program Library. It should be within the first three pages still. If you can't find it, I'll dig it up and link you to it.