AsyncFunction may cause app crash if #VALUE calcError exists in spreadsheet

Posted by: tovarnakm on 21 June 2022, 3:17 am EST

  • Posted 21 June 2022, 3:17 am EST

    Hi all,

    I would like to report a spreadJS issue related to GC.Spread.CalcEngine.Functions.AsyncFunction, because if random #VALUE with calcError occurs in the spreadsheet, the application crashes with error calculateDirtyNodes when the result of async custom formula is evaluated using context.setAsyncResult(). If I evaluate the result as Promise.resolve().then (() => context.setAsyncResult()) the application does not crash.

    Codesandbox: https://codesandbox.io/s/designer-react-sample-forked-ytyf04?file=/src/App.js

    To replicate, please comment out line 142 and uncomment 140.

    Thank you for you help!
  • Replied 21 June 2022, 3:42 pm EST

    Hi Martin,

    This behavior is by design. The reason of using the async function is that because the calculation process of an async function is asynchronous.

    Hence, the setAsyncResult is designed to solve this case, it must be used in an async environment i.e., setTimeout, http request, http post...etc.,

    Simply execute the
    context.setAsyncResult("1")
    inside setTimeout and it will work fine. For example, you can refer to the following sample: https://jscodemine.grapecity.com/share/AODXvbeUp0KfEHPmg7R25Q/

    Also, could you please explain what you are trying to accomplish so that we can have a better understanding of your use case and could assist you accordingly.

    Regards
    Ankit
  • Marked as Answer

    Replied 21 June 2022, 6:23 pm EST

    Sure, makes sense. Thank you!
  • Replied 28 June 2022, 12:21 am EST

    Hello,

    we have next issue, if we have more cells where setAsyncResult is executed, the app freeze and cells show value after some time (more then 1 minute).
    Martin did what you recommended with Promise.resolve().then() function, but it's causing the next issue I wrote above.
    After removing Promise, values in the cells are shown immediately, but we do have Martin's issue again.

    I also forked Martin's codesandbox and execute the function more times and it takes longer time and it's freezing as well.
    LINK -> https://codesandbox.io/s/designer-react-sample-forked-ci21lv?file=/src/App.js

    Could you please help us to solve this issue?
    Thank you very much!

    Regards
    Richard
  • Replied 28 June 2022, 6:12 pm EST

    Hi Richard,

    While setting a large amount of formulas and values, the best practice is to use the suspendCalcService/resumeCalcService methods and suspendPaint/resumePaint methods for performance enahancement.

    The suspendCalcService method will stop the calculation process until the formula settings are complete. Later, the resumeCalcService method can be called to restore the calculation system. Both of these methods enhance performance to a great extent especially when users have massive worksheets with a lot of formulas.

    The suspendPaint method allows users to stop the repaint process while the modifications are being done. After integrating all the changes, users can invoke the resumePaint method. Both of these methods enhance the overall performance because Spread will now paint only once after all the changes have been done.

    Using these methods and the sample that you provided, I checked with the latest version of SpreadJS(V15.1.2) and the performance was highly improved( not taking 1 minute as mentioned by you.): https://jscodemine.grapecity.com/share/XsGLiJpK9k2ascgqxFkuXA/

    In the sample, when you click the "setFormula" button, it will show "Loading..." for all the cells despite suspending the calc service and paint. This is a know issue to us for which the tracking id is: SJS-13266. The devs are working on fixing this issue. We will let you know when we have an update for you.

    API Docs:

    suspendPaint and resumePaint: https://www.grapecity.com/spreadjs/docs/latest/online/UsingsuspendPaintandresumePaint.html

    Set Large Amounts of Formulas: https://www.grapecity.com/spreadjs/docs/latest/online/SettingLargeAmountsofFormulas.html

    Regards
    Ankit
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels