Add a promisified put() to GunSmith
This commit is contained in:
parent
4562b0d544
commit
91e2ec08c5
3 changed files with 34 additions and 0 deletions
|
|
@ -612,6 +612,17 @@ function createReplica(path, afterMap = false) {
|
|||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
pPut(data) {
|
||||
return new Promise((res, rej) => {
|
||||
this.put(data, ack => {
|
||||
if (ack.err) {
|
||||
rej(new Error(ack.err))
|
||||
} else {
|
||||
res()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -408,4 +408,22 @@ describe('gun smith', () => {
|
|||
done()
|
||||
release()
|
||||
})
|
||||
|
||||
it('provides an special thenable put()', async done => {
|
||||
expect.assertions(1)
|
||||
await whenReady()
|
||||
|
||||
const a = words()
|
||||
const b = words()
|
||||
const node = instance.get(a).get(b)
|
||||
const value = words()
|
||||
|
||||
await node.pPut(value)
|
||||
|
||||
const res = await node.then()
|
||||
|
||||
expect(res).toBe(value)
|
||||
done()
|
||||
release()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@ namespace Smith {
|
|||
* if needed.
|
||||
*/
|
||||
specialThen(): Promise<GunT.ListenerData>
|
||||
/**
|
||||
* A promise version of put().
|
||||
* @throws
|
||||
*/
|
||||
pPut(data: GunT.ValidDataValue): Promise<void>
|
||||
}
|
||||
|
||||
export type UserSmithNode = GunSmithNode & GunT.UserGUNNode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue