Jump to content




Daemon API


12 replies to this topic

#1 HDeffo

  • Members
  • 214 posts

Posted 07 February 2016 - 11:01 PM

There have been several of these most of which are buried and hidden in the forums however, I usually notice they aren't very flexible either by not filtering out events passed to them or like the parallel API not dynamic and limiting the number of background processes that can be run. So here is the code i personally use when i need to run several things at once in case anyone on here is ever interested in using it as well

pastebin get nByRT66R



VERY simple to use and very short code.

os.loadAPI("daemon")
--#starts the daemon change the string to whatever you named the file

daemon.add(function[, error])
--#starts a function in the background which will loop until the function reaches its end
--#error is a function that will be ran if the coroutine ends, it is passed the error code 

daemon.rem(table)
--#removes a currently running coroutine
--#pass it the table returned by daemon.add

daemon.getBackground()
--#returns a table of all coroutines currently in the background as well as the event they are waiting for to continue running





example:
Spoiler

Edited by HDeffo, 11 August 2018 - 02:02 AM.


#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 07 February 2016 - 11:53 PM

Does the function
add
start the whole thing?

Edited by Creator, 07 February 2016 - 11:53 PM.


#3 HDeffo

  • Members
  • 214 posts

Posted 07 February 2016 - 11:56 PM

os.loadAPI("daemon")

is what starts the code however, it doesnt actually do anything significant besides rewriting os.pullEventRaw until you add a background function. ill add an example to the top to show you how it works

Edited by HDeffo, 08 February 2016 - 12:01 AM.


#4 HDeffo

  • Members
  • 214 posts

Posted 08 February 2016 - 12:43 AM

Just fixed a bug where it would return events several times to each background function >.> just had to move the inPullEvent variable oops

#5 Lupus590

  • Members
  • 1,974 posts
  • LocationUK

Posted 08 February 2016 - 08:46 AM

This looks like it could be very useful in an os

#6 HDeffo

  • Members
  • 214 posts

Posted 08 February 2016 - 01:00 PM

View PostLupus590, on 08 February 2016 - 08:46 AM, said:

This looks like it could be very useful in an os

Thats actually one of the things I frequently use it for. As well as when I need quite a few functions which require pull events.

#7 Lupus590

  • Members
  • 1,974 posts
  • LocationUK

Posted 08 February 2016 - 01:17 PM

What's the license? Would I be able to use this in Hive?

#8 HDeffo

  • Members
  • 214 posts

Posted 08 February 2016 - 05:21 PM

View PostLupus590, on 08 February 2016 - 01:17 PM, said:

What's the license? Would I be able to use this in Hive?

its very simple code so I didn't bother with a license if you want to put credits in there for me I would appreciate it but feel free to use the code however you please :3

#9 Lupus590

  • Members
  • 1,974 posts
  • LocationUK

Posted 08 February 2016 - 05:47 PM

View PostHDeffo, on 08 February 2016 - 05:21 PM, said:

View PostLupus590, on 08 February 2016 - 01:17 PM, said:

What's the license? Would I be able to use this in Hive?

its very simple code so I didn't bother with a license if you want to put credits in there for me I would appreciate it but feel free to use the code however you please :3

default license for things is all rights reserved, unless you explicitly say what we can do with your code we could be breaking laws just by compiling/running it (depending on where the person compiling your code lives) try this site: http://choosealicense.com/

Edited by Lupus590, 08 February 2016 - 05:47 PM.


#10 HDeffo

  • Members
  • 214 posts

Posted 08 February 2016 - 06:58 PM

well i put it in my signature for now :P I really feel like I don't need to worry about licensing on something im making in a game so thats just where i leave it.

#11 Lupus590

  • Members
  • 1,974 posts
  • LocationUK

Posted 08 February 2016 - 08:56 PM

That's very descriptive, but sounds like the MIT license (which is very short so consider reading it)

#12 HDeffo

  • Members
  • 214 posts

Posted 08 February 2016 - 08:58 PM

Yeah I know what the MIT license is, I just prefer to try and stay out of the bureaucracy as much as possible except on things that I really care if someone stole

#13 HDeffo

  • Members
  • 214 posts

Posted 11 August 2018 - 02:16 AM

someone recently pointed out this old thing didn't handle coroutines that reached an end well what so ever. so now it does!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users