Meteor - Cancelling a Server Method from the Client

前端 未结 2 1948
北荒
北荒 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: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.

提交回复
热议问题