1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

fix listen once

This commit is contained in:
Sebastian Gerske 2018-11-23 14:28:41 +01:00
parent 0c3c21b4c5
commit 17f1b3e53e
3 changed files with 15 additions and 7 deletions

View File

@ -26,10 +26,12 @@ export default class Event {
this.interval)
}
public async listenOnce() {
public listenOnce(callback: any) {
this.listen((events: any[]) => {
EventListener.unsubscribe(this)
return events
if (events) {
EventListener.unsubscribe(this)
callback(events[0])
}
})
}

View File

@ -124,7 +124,7 @@ export default class Ocean {
const storedDdo = await aquarius.storeDDO(ddo)
Logger.log(JSON.stringify(storedDdo, null, 2))
// Logger.log(JSON.stringify(storedDdo, null, 2))
await didRegistry.registerAttribute(
assetId,

View File

@ -52,19 +52,25 @@ describe("EventListener", () => {
describe("#listenOnce()", () => {
xit("should listen once", async () => {
it("should listen once", (done) => {
const acc = accounts[1]
const countBefore = EventListener.count()
const event = EventListener.subscribe("OceanToken",
"Transfer",
{
to: acc.getId(),
})
const events = await event.listenOnce()
event.listenOnce(
(data: any) => {
assert(events, "no events")
assert(data)
assert(data.blockNumber)
assert(EventListener.count() === countBefore)
done()
})
const {market} = keeper