Meteor - Cancelling a Server Method from the Client

前端 未结 2 1945
北荒
北荒 2021-02-13 22:51

I\'m performing a database count through a server method. Users can select how they want the count to be performed and then invoke the method.

My problem is that the cou

相关标签:
2条回答
  • 2021-02-13 23:33

    Cancelling an already-made method call to server from client is not possible.

    But if your method are called multiple times in a short interval, and you only care about the last call's result. You could use debounce to delay execution for some times. This will help reduce unnecessary calls to server.

    0 讨论(0)
  • 2021-02-13 23:38

    More of a work around, but if you had a reactive variable (could be an entry in the DB) that is a status of the method, and in the method itself, you check for that flag every chance you get for the status.

    {
        _id: "some id for the method", running: true
    }
    

    Pseudocode for method

    Meteor.methods({
        method: (_id) => {
            status = getStatusForId(_id);
            while(status) {
                status = getStatusForId(_id);
            }
        }
    });
    

    Then to stop it, you just update that flag to be false and the method will stop as soon as it can.

    0 讨论(0)
提交回复
热议问题