File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,13 @@ export default class Microlock extends EventEmitter {
133
133
return resolve ( val )
134
134
} ) ;
135
135
} )
136
- . catch ( ( ) => this . __throwAlreadyLocked ( ) ) ;
136
+ . catch ( ( e ) => {
137
+ // Key already exists
138
+ if ( e . errorCode === 105 ) {
139
+ this . __throwAlreadyLocked ( ) ;
140
+ }
141
+ throw e ;
142
+ } ) ;
137
143
}
138
144
139
145
unlock ( ) {
@@ -143,12 +149,18 @@ export default class Microlock extends EventEmitter {
143
149
return resolve ( res ) ;
144
150
} ) ;
145
151
} )
146
- . catch ( ( ) => this . __throwLockNotOwned ( ) ) ;
152
+ . catch ( ( e ) => {
153
+ // KeyNotFound or CompareFailed
154
+ if ( e . errorCode === 100 || e . errorCode === 101 ) {
155
+ this . __throwLockNotOwned ( ) ;
156
+ }
157
+ throw e ;
158
+ } ) ;
147
159
}
148
160
149
161
renew ( ) {
150
162
return new Promise ( ( resolve , reject ) => {
151
- return this . __etcd . set ( this . __key , this . __node_id , {
163
+ return this . __etcd . set ( this . __key , null , {
152
164
prevValue : this . __node_id ,
153
165
refresh : true ,
154
166
ttl : this . __ttl
@@ -157,6 +169,12 @@ export default class Microlock extends EventEmitter {
157
169
return resolve ( val ) ;
158
170
} )
159
171
} )
160
- . catch ( ( ) => this . __throwLockNotOwned ( ) ) ;
172
+ . catch ( ( e ) => {
173
+ // KeyNotFound or CompareFailed
174
+ if ( e . errorCode === 100 || e . errorCode === 101 ) {
175
+ this . __throwLockNotOwned ( ) ;
176
+ }
177
+ throw e ;
178
+ } ) ;
161
179
}
162
180
}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import Microlock, {
12
12
InvalidTtlError ,
13
13
AlreadyLockedError ,
14
14
LockNotOwnedError
15
- } from '../../lib /microlock' ;
15
+ } from '../../src /microlock' ;
16
16
17
17
describe ( 'microlock' , ( ) => {
18
18
let etcd = null
You can’t perform that action at this time.
0 commit comments