retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
9.98k stars 651 forks source link

Why are we using abort? #303

Closed akshayred closed 5 years ago

akshayred commented 5 years ago
editor.on('process nodecreated noderemoved connectioncreated connectionremoved', async () => {
                        await engine.abort();
                        await engine.process(editor.toJSON());
                        //setting value of rule data from retejs graph
                        jQuery('#ifthenelse-data').val(JSON.stringify(editor.toJSON()));
                });

In above example why are we using engine.abort();

Ni55aN commented 5 years ago

Nodes' worker can be async, therefore process() is async. And formally, you can call the process again, without waiting for the previous done, but this will lead to conflict. Therefore, you must cancel the processing of the previous

Ni55aN commented 5 years ago

https://rete.js.org/#/docs/engine

In general, for each change in the schema (nodes, connections, node data), it is necessary to perform processing. Due to the fact that workers can be asynchronous, the 'process' method is also asynchronous. Since the actions provoking the processing can be performed without waiting for the completion of the previous processing, we need the abort method, which waits for the completion of the previous processing and guarantees data integrity.