mirror of
https://github.com/hackku21/loc-chain-backend.git
synced 2024-10-27 20:34:03 +00:00
Wrap complex push in trylock
This commit is contained in:
parent
1bba0a18ec
commit
f072d81b5f
@ -20,6 +20,10 @@ export interface FirebaseResourceItem {
|
||||
export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T> {
|
||||
protected refName!: RTDBRef
|
||||
|
||||
get firebase() {
|
||||
return Application.getApplication().make<FirebaseUnit>(FirebaseUnit)
|
||||
}
|
||||
|
||||
/** Get the Reference for this resource. */
|
||||
ref(): firebase.database.Reference {
|
||||
return Application.getApplication().make<FirebaseUnit>(FirebaseUnit).ref(this.refName)
|
||||
@ -75,6 +79,8 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
|
||||
* @param item
|
||||
*/
|
||||
async push(item: T): Promise<T> {
|
||||
await this.firebase.trylock(this.refName)
|
||||
|
||||
await this.ref().transaction((collection) => {
|
||||
if ( !collection ) collection = []
|
||||
item.seqID = this.findNextId(collection)
|
||||
@ -97,6 +103,7 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
|
||||
})
|
||||
})
|
||||
|
||||
await this.firebase.unlock(this.refName)
|
||||
return item
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user