Facility Control

 View Only
  • 1.  async.exec - limited to one async?

    Posted 04-06-2019 21:51

    So, I'm well aware of the async.exec, and how to call on functions etc that can then include pause events in them.

    And they can really be amazing. Just got one question though...
    Are we limited to one asynchronous execution? Or is there a way to run more than one at a time?
    Now in most cases that would most definetly not be needed. But say, if I wanted something that waits say 3 seconds before firing. Is there a way to run ANOTHER async in the background that doesnt wait for the first one to finish?

    It's not a problem, but something that would be nice to know for certain before starting a new DashBoard project?
    And say, if I have two DashBoards, do they run separatly?
    Do they run separatly even if I choose one as the datasource for the other?
    Could I have one DashBoard running an analysis on a listener, with its own executor and async.exec, while the main DashBoard still runs two as well?
    Simple testing suggest I can at least run two DashBoards at the same time with their own async exec, and still output to the same debug window. Sooooo, I assume I could then do the same with the suggestion above and have one "listener" DashBoard that does the analysis of a TCP stream, while the main DashBoard handles the commands etc for connecting and timing say camera cuts etc...

    All in all, what are the limits here?



  • 2.  RE: async.exec - limited to one async?

    Ross Staff
    Posted 04-07-2019 19:16

    Hi Aleksander

    You are correct that each custom panel has a single shared thread for ogscript.asyncExec.

    Recognizing that there may be a need to run several tasks like this, we have added the ability to create additional asyncExec threads with:

    var executor = ogscript.createAsyncExec('ASYNC_EXEC_ID'); //ONLY USED TO CREATE NEW

    and 

    var executor = ogscript.getAsyncExecById('ASYNC_EXEC_ID'); //USED TO GET ONCE CREATED

    Once you have your executor object, you can essentially use it like the ogscript.asyncExec:

    executor.asyncExec(function, delay);

    We've also given it more advanced features such as taking/releasing locks, waiting for work, etc. But, if your goal is to start with simply having more asyncExec threads, this will get you what you want.

     


    #DashBoard


  • 3.  RE: async.exec - limited to one async?

    Posted 04-18-2019 19:25

    If I try to use ogscript.getAsyncExec to get the object I created using ogscript.createAsyncExec I get this error:

    TypeError: Cannot find function getAsyncExec in object OGScriptCommands

    Is that the correct function name? I'm on Dashboard 8.5.1.


    #DashBoard


  • 4.  RE: async.exec - limited to one async?

    Ross Staff
    Posted 04-18-2019 19:37

    Hi Joseph.

    Very sorry - there appear to be 2 typos in my post.

    It should  be 

    getAsyncExecById

    And 

    executor.asyncExec(function, delay);

    #DashBoard


  • 5.  RE: async.exec - limited to one async?

    Posted 04-18-2019 19:41

    That worked, thanks!


    #DashBoard


  • 6.  RE: async.exec - limited to one async?

    Posted 04-24-2019 19:08

    Hello James, 

    Referring to that :  "We've also given it more advanced features such as taking/releasing locks, waiting for work, etc." 

    I have a panel with about 20 asynExec's tasks that uses to schedule and automate records and exports scenario on my video servers every day (they re-schedule themselves for tomorrow after each execution).

    Maybe there is a function to get countdown (how much time left to execution) for 'ogscript.createAsyncExec' object? It can be a very nice option, to see timer countdown to the execution. 

     

    Thanks!


    #DashBoard


  • 7.  RE: async.exec - limited to one async?

    Posted 05-02-2019 13:45


  • 8.  RE: async.exec - limited to one async?

    Ross Staff
    Posted 05-02-2019 20:04

    There is no ability to get the time until the next execution. The more advanced features are about making blocking calls to wait for work and taking/releasing locks.

    Here are the available functions as of DashBoard 8.5.1:

     

    Here is an example panel that shows using the executor's getWork() and takeLock/releaseLock features:

    <abs contexttype="opengear" style="">
    <simplegrid cols="3" height="177" left="14" rows="2" top="16" width="767">
    <button buttontype="push" height="265" left="21" name="Create Thread" top="21" width="449">
    <task tasktype="ogscript">var executor = ogscript.createAsyncExec("test");
    executor.asyncExec(function()
    {
    ogscript.debug("THREAD STARTED");

    var work = executor.getWork();
    while (work != null)
    {
    executor.takeLock("MY_LOCK_ID"); //TAKE THE LOCK
    ogscript.debug("GOT WORK - WAITING ON LOCK");

    var lockReleased = executor.waitOnLock(5000); //WAIT FOR THE LOCK TO BE RELEASED

    if (lockReleased)
    {
    ogscript.debug("LOCK RELEASED - " + work);
    }
    else
    {
    ogscript.debug("LOCK TIMED OUT WITHOUT WORK");
    }

    work = executor.getWork();
    }

    ogscript.debug("THREAD EXITING");
    }
    );</task>
    </button>
    <button buttontype="push" height="285" left="604" name="Add Work" top="45" width="334">
    <task tasktype="ogscript">var async = ogscript.getAsyncExecById("test");
    if (async != null)
    {
    async.putWork("NEW WORK! " + (new Date()).getTime());
    }
    else
    {
    ogscript.debug("NO ASYNC EXECT THREAD");
    }
    </task>
    </button>
    <button buttontype="push" height="285" left="975" name="Release Lock" top="346" width="334">
    <task tasktype="ogscript">var async = ogscript.getAsyncExecById("test");
    if (async != null)
    {
    async.releaseLock("MY_LOCK_ID");
    }
    else
    {
    ogscript.debug("NO ASYNC EXECT THREAD");
    }</task>
    </button>
    <button buttontype="push" height="291" left="133" name="Close Thread" top="407" width="366">
    <task tasktype="ogscript">var async = ogscript.getAsyncExecById("test");
    if (async != null)
    {
    async.close();
    }
    else
    {
    ogscript.debug("NO ASYNC EXECT THREAD");
    }</task>
    </button>
    <button buttontype="push" height="285" left="967" name="Release Lock (BAD)" top="42" width="334">
    <task tasktype="ogscript">var async = ogscript.getAsyncExecById("test");
    if (async != null)
    {
    async.releaseLock("BAD_LOCK_ID"); //Releasing a lock that doesn't exist
    }
    else
    {
    ogscript.debug("NO ASYNC EXECT THREAD");
    }</task>
    </button>
    </simplegrid>
    </abs>

    #DashBoard


  • 9.  RE: async.exec - limited to one async?

    Posted 12-18-2023 03:43

    Hi again James!

    Comming back to this one from 4 years agow now.
    Can this be used to create a executor.asyncHTTP as well?

    Tried using your formula above to create another executor and use that to call the asyncHTTP, but I get error messages no matter what.



    ------------------------------
    Aleksander Stalsberg
    Inland Norway University of Applied Sciences/Lillehammer Icehockey Club
    Norway
    ------------------------------



  • 10.  RE: async.exec - limited to one async?

    Posted 05-05-2019 16:40

    Thanks, James!


    #DashBoard