Moving to async/await on client side but get weird error

if (shift21) {
          campersInRoom.forEach(async (doc) => {
            try {
              await Meteor.callAsync('changeShift', doc.FullName, props.campLabel, shift21);
              messageApi.open({ type: 'success', content: `Room ${radio} changed` });
            } catch (error) {
              messageApi.open({ type: 'error', content: `Something went wrong. ${error}` });
            }
            // Meteor.call('changeShift', doc.FullName, props.campLabel, shift21, (err) => {
            //   if (err) {
            //     messageApi.error(err.reason);
            //   }
            // });
          });
        }

Generates client side error: “Exception while simulating the effect of invoking ‘changeShift’ Error: Called saveOriginals twice without retrieveOriginals”

Anyone familiar with this error?

Oh, perhaps this isn’t waiting for the asynchronous operation…

Maybe a for of loop.

Yeah you’ll need a for…of to process sequentially.

1 Like

If you want to call the methods in parallel, you can fix the error by adding zodern:fix-async-stubs to your app: GitHub - zodern/fix-async-stubs: Package to remove limitations with async stubs in Meteor

It’s the same solution Meteor 3 ended up using to remove the limitations with async method calls.

3 Likes