A
A
Alecxandrys2017-03-16 14:24:27
JavaScript
Alecxandrys, 2017-03-16 14:24:27

Why is there a double function call?

Good afternoon,
There is a given call to a method on the server

Meteor.call('ActionOn',{
                deck:game.chosenCardId.deck,
                index:game.chosenCardId.index
            },{
                deck:model.deck,
                index:model.index
            },state.type,false,function(error,result)
            {
                if(!error)
                {
                    if(result)
                    {
                        log.push(result);
                        if(result == "Success")
                        {
                            log.push("Model successfully action");
                        }
                    }
                    else
                    {
                        log.push("Status of shooting unknown");
                    }
                }
                else if(error.error == "battle_exist_error")
                {
                    log.push("ID check unsuccesfull");
                }
                else if(error.error == 'order_error')
                {
                    log.push("This model can't turning now, because another have priority");
                }
                else if(error.error == 'immovable')
                {
                    log.push("Model is immovable");
                }
                else if(error.error == 'type_unidentified')
                {
                    log.push("This type of action isn't supported");
                }
                else
                {
                    log.push("Unidentified error rise from server");
                }
                _logDep.changed();
                _turnDep.changed();
            });

Accordingly, Meteor.methods is described on the server side with the appropriate name and parameters.
The problem is that for some reason the method is called twice, sequentially.
In most situations, this leads to the fact that after working correctly the first time, the second time turns the result into a mess.
What is the reason for this behavior and how to solve the problem?
UPD: The call stack extends from this Meteor.call(), the set of parameters is the same.
Also, the callback, which should work, reacts only to return from the secondcall, which in most cases returns Meteor.error, which leads to the result in the form of displaying an error of some kind to the user (most often with the order of the move), but the results of the first call that passed correctly are brought up to date and displayed again user.
This creates a visible difference when wrong actions are reported, but the action itself is done.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alecxandrys, 2017-03-26
@Alecxandrys

By default, Meteor.call after 30 seconds, if there is a callback, without receiving a response from the server, makes a second call with the same set of parameters.
The reason for this delay is not important, even if it is caused by debugging on the server side through the IDE.
It is cured by using Meteor.apply (), in which you can specify the noRetry parameter, which will prevent this behavior.

S
Stepanya, 2017-03-16
@Stepanya

First, in the debugger, find out who is calling this function, and secondly, fix this call

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question