Add a promisified put() to GunSmith

This commit is contained in:
Daniel Lugo 2021-09-17 16:15:43 -04:00
parent 4562b0d544
commit 91e2ec08c5
3 changed files with 34 additions and 0 deletions

View file

@ -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()
}
})
})
}
}
}

View file

@ -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()
})
})

View file

@ -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