• v15.3.0 Stable

    rayaman released this 2022-12-31 02:21:01 -05:00 | 0 commits to v15.3.0 since this release

    Update 15.3.0 - A world of Connections

    Full Update Showcase

    multi, thread = require("multi"):init{print=true}
    GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
    
    local conn = multi:newSystemThreadedConnection("conn"):init()
    
    multi:newSystemThread("Thread_Test_1",function()
    	local multi, thread = require("multi"):init()
    	local conn = GLOBAL["conn"]:init()
    	conn(function()
    		print(THREAD:getName().." was triggered!")
    	end)
    	multi:mainloop()
    end)
    
    multi:newSystemThread("Thread_Test_2",function()
    	local multi, thread = require("multi"):init()
    	local conn = GLOBAL["conn"]:init()
    	conn(function(a,b,c)
    		print(THREAD:getName().." was triggered!",a,b,c)
    	end)
    	multi:newAlarm(2):OnRing(function()
    		print("Fire 2!!!")
    		conn:Fire(4,5,6)
    		THREAD.kill()
    	end)
    
    	multi:mainloop()
    end)
    
    conn(function(a,b,c)
    	print("Mainloop conn got triggered!",a,b,c)
    end)
    
    alarm = multi:newAlarm(1)
    alarm:OnRing(function()
    	print("Fire 1!!!")
    	conn:Fire(1,2,3) 
    end)
    
    alarm = multi:newAlarm(3):OnRing(function()
    	multi:newSystemThread("Thread_Test_3",function()
    		local multi, thread = require("multi"):init()
    		local conn = GLOBAL["conn"]:init()
    		conn(function(a,b,c)
    			print(THREAD:getName().." was triggered!",a,b,c)
    		end)
    		multi:newAlarm(2):OnRing(function()
    			print("Fire 3!!!")
    			conn:Fire(7,8,9)
    		end)
    		multi:mainloop()
    	end)
    end)
    
    multi:newSystemThread("Thread_Test_4",function()
    	local multi, thread = require("multi"):init()
    	local conn = GLOBAL["conn"]:init()
    	local conn2 = multi:newConnection()
    	multi:newAlarm(2):OnRing(function()
    		conn2:Fire()
    	end)
    	multi:newThread(function()
    		print("Conn Test!")
    		thread.hold(conn + conn2)
    		print("It held!")
    	end)
    	multi:mainloop()
    end)
    
    multi:mainloop()
    

    Added

    • multi:newConnection():Unconnect(conn_link) Fastmode previously didn't have the ability to be unconnected to. This method works with both fastmode and non fastmode. fastMode will be made the default in v16.0.0 (This is a breaking change for those using the Destroy method, use this time to migrate to using Unconnect())

    • thread.chain(...) allows you to chain thread.hold(FUNCTIONs) together

      while true do
      	thread.chain(hold_function_1, hold_function_2)
      end
      

      If the first function returns true, it moves on to the next one. if expanded it follows:

      while true do
      	thread.hold(hold_function_1)
      	thread.hold(hold_function_2)
      end
      
    • Experimental option to multi settings: findopt. When set to true it will print out a message when certain pattern are used with this library. For example if an anonymous function is used in thread.hold() within a loop. The library will trigger a message alerting you that this isn't the most performant way to use thread.hold().

    • multi:newSystemThreadedConnection()

      Allows one to trigger connection events across threads. Works like how any connection would work. Supports all of the features, can even be added with non SystemThreadedConnections as demonstrated in the full showcase.

    • multi:newConnection():SetHelper(func)

      Sets the helper function that the connection object uses when creating connection links.

    • multi.ForEach(table, callback_function)

      Loops through the table and calls callback_function with each element of the array.

    • If a name is not supplied when creating threads and threaded objects; a name is randomly generated. Unless sending through an established channel/queue you might not be able to easily init the object.

    Changed

    • Internally all OnError events are now connected to with multi.print, you must pass print=true to the init settings when initializing the multi object. require("multi"):init{print=true}

    • All actors now use fastmode on connections

    • Performance enhancement with processes that are pumped. Instead of automatically running, by suppressing the creation of an internal loop object that would manage the process, we bypass that freeing up memory and adding a bit more speed.

    • Connection:fastMode() or Connection:SetHelper() now returns a reference to itself

    • Connection:[connect, hasConnections, getConnection] changed to be Connection:[Connect, HasConnections, getConnections]. This was done in an attempt to follow a consistent naming scheme. The old methods still will work to prevent old code breaking.

    • Connections when added(+) together now act like 'or', to get the 'and' feature multiply(*) them together.

      Note: This is a potentially breaking change for using connections.

      multi, thread = require("multi"):init{print=true}
      -- GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
      
      local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection(), multi:newConnection()
      
      thread:newThread(function()
      	print("Awaiting status")
      	thread.hold(conn1 + (conn2 * conn3))
      	print("Conn or Conn2 and Conn3")
      end)
      
      multi:newAlarm(1):OnRing(function()
      	print("Conn")
      	conn1:Fire()
      end)
      
      multi:newAlarm(2):OnRing(function()
      	print("Conn2")
      	conn2:Fire()
      end)
      
      multi:newAlarm(3):OnRing(function()
      	print("Conn3")
      	conn3:Fire()
      end)
      

    Removed

    • Connection objects methods removed:
      • holdUT(), HoldUT() -- With the way thread.hold(conn) interacts with connections this method was no longer needed. To emulate this use multi.hold(conn). multi.hold() is able to emulate what thread.hold() outside of a thread, albeit with some drawbacks.

    Fixed

    • SystemThreaded Objects variables weren't consistent.
    • Issue with connections being multiplied only being able to have a combined fire once

    ToDo

    • Work on network parallelism (I am really excited to start working on this. Not because it will have much use, but because it seems like a cool addition/project to work on. I just need time to actually do work on stuff)
    Downloads