-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
29 lines (23 loc) · 861 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Mongo } from 'meteor/mongo';
let _withTxn = false;
// here to support isomorphic code but transactions only truly run on the server
export const inTransaction = () => false;
export const withTransaction = async fn => {
_withTxn = true;
return await fn();
}
// in Meteor 2.x, for some reason, I was seeing write fails from Meteor._debug even though they were succeeding
// so this supressess the errors on the client for the function that runs inside withTransaction
if (!Meteor.isFibersDisabled) {
const originalMeteorDebug = Meteor._debug;
Meteor._debug = function (m, s) {
if (_withTxn && s.reason === 'Access denied') {
setTimeout(() => _withTxn = false, 1)
return;
} else {
return originalMeteorDebug.call(this, m, s)
}
}
}
Mongo.inTransaction = inTransaction;
Mongo.withTransaction = withTransaction;