Avoiding a javascript race condition

后端 未结 7 2240
醉话见心
醉话见心 2020-12-23 12:26

Here\'s the scenario:

My users are presented a grid, basically, a stripped down version of a spreadsheet. There are textboxes in each row in the grid. When they ch

7条回答
  •  庸人自扰
    2020-12-23 12:52

    When working with async data sources you can certainly have race conditions because the JavaScript process thread continues to execute directives that may depend on the data which has not yet returned from the remote data source. That's why we have callback functions.

    In your example, the call to the validation code needs to have a callback function that can do something when validation returns.

    However, when making something with complicated logic or trying to troubleshoot or enhance an existing series of callbacks, you can go nuts.

    That's the reason I created the proto-q library: http://code.google.com/p/proto-q/

    Check it out if you do a lot of this type of work.

提交回复
热议问题