Gun: undefined returned when using put as returning a promise

Created on 2 Jun 2019  Â·  8Comments  Â·  Source: amark/gun

here's a demo of a bug in ".then" it happens when hammering with concurrent puts.
https://codesandbox.io/s/gundbputundefinedthenerror-gnvpk
It happened to me when load testing our server. if you treat put(...) as "promise" either by doing await or adding .then() then put() sometimes returns undefined. and you get exception "cannot call then of undefined".
puts callbacks are returned ok. The demo prints the errors, summarize how many undefined and also counts the callbacks.

Most helpful comment

@Dletta you forgot the new Promise in your snippet
@jacobpdq
Here are our gun extensions it includes
.putAck
.secretAck
.decrypt -> opposite of secretAck

https://github.com/GoodDollar/GoodDAPP/blob/master/src/lib/gundb/gundb-extend.js

All 8 comments

@amark
can you comment on this?

@sirpy I think @Dletta @jacobpdq getting this also.

I just told them in chat that .put( doesn't actually support .then on it. .then is for reading only. So I'd actually like to classify this as "not a bug" and close it.

Or maybe somebody else can help contribute to this as a feature addition?

@amark you are right, i've actually implemented in the past putAck (ie a put that returns a promise) in order to solve it but I forgot:)

@sirpy thanks, I super appreciate that.

You should share your putAck module with @Dletta @jacobpdq and the rest of the community, as they'd find it valuable!

Yeah definitely... I was... awaiting it

On Thu, Aug 29, 2019, 3:24 PM Mark Nadal notifications@github.com wrote:

@sirpy https://github.com/sirpy thanks, I super appreciate that.

You should share your putAck module with @Dletta
https://github.com/Dletta @jacobpdq https://github.com/jacobpdq and
the rest of the community, as they'd find it valuable!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/amark/gun/issues/758?email_source=notifications&email_token=AABIC3DOQKOZBOVSVOO3HYTQHAO7ZA5CNFSM4HSCUSOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5PRVVQ#issuecomment-526326486,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABIC3D43MADZXQYEHLXKLTQHAO7ZANCNFSM4HSCUSOA
.

ROFL

Here my code for an put that returns a Promise that either:

  • Resolves and returns an object containing a gunRef of the item you put in and the ack of the item you put in
  • Rejects and returns ack.err if error occured
Gun.chain.ackPut = async function (item) {
  var gun = this;
  gun.put(item, function(ack) {
    return (new Promise((res, rej)=>{
    if(ack.err){rej(ack.err)}
    res({reference:gun, ack:ack})
    }))
  })
}

@Dletta you forgot the new Promise in your snippet
@jacobpdq
Here are our gun extensions it includes
.putAck
.secretAck
.decrypt -> opposite of secretAck

https://github.com/GoodDollar/GoodDAPP/blob/master/src/lib/gundb/gundb-extend.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linonetwo picture linonetwo  Â·  4Comments

ivkan picture ivkan  Â·  6Comments

corporatepiyush picture corporatepiyush  Â·  6Comments

Xsmael picture Xsmael  Â·  3Comments

terrybleger picture terrybleger  Â·  5Comments