Giter VIP home page Giter VIP logo

Comments (2)

bmatusiak avatar bmatusiak commented on May 25, 2024

gun is not promise/async based..

the best way to handle async stuff is to wrap with your own promise logic like this example

var Gun = require("gun")
var gun = Gun();

async function getData() {
    return new Promise((res) => {
        var chain = gun.get("test").get("hello").on((data) => {
            if (data) {
                chain.off();
                res(data)
            }
        })
    })
}

async function putData(data) {
    gun.get("test").get("hello").put(data)
    return await getData()
}

async function run() {
    var data = await putData("world");
    console.log(data)
}

run();

from gun.

gustavcorpas avatar gustavcorpas commented on May 25, 2024

gun is not promise/async based..

the best way to handle async stuff is to wrap with your own promise logic like this example

I believe this is very close to what is implemented already in gun.then and what I think is used to "trick" js into woking with await's - because for the most part awaiting works fine. see docs

I realized however, that the issue is not so much a problem with await but that in general the .on call is not fired!

This does not work:

gun.get("foo").get("name").on(name => console.log("name is: ", name)); // never runs

const thing = gun.get("thing").get("element").put("alice");
gun.get("foo").get("name").put(thing);       

from gun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.