小编men*_*urg的帖子

带有await的firebase on('value')不能按预期工作

我正在寻找构建函数,等待所有值都打开('value'),然后转到下一行,换句话说是异步函数.

 let upcomingGamesList = await firebase.database().ref('UpcomingGames').on('value', snapshot => {
        upcomingGamesList = snapshot.val()
        console.log('upcoming t1',upcomingGamesList)
        return upcomingGamesList
    })
    console.log('upcoming t2',upcomingGamesList)
    let upcomingPreferences = upcomingGamesList.map(async(game) => {
        console.log(game)
        let GameId = game.GameId
        await firebase.database().ref(`GameNotificationPreferances/${GameId}`).orderByKey().equalTo(UserStore.user.uid).once('value', snapshot => {
            if (snapshot.val() != null || snapshot.val() != undefined) {
                conosle.log(snapshot.val())
            } else {
                console.log('not value')
            }
        })
        console.log(game)
    })
Run Code Online (Sandbox Code Playgroud)

发生了什么是即将到来的t2

        console.log('upcoming t2',upcomingGamesList)
Run Code Online (Sandbox Code Playgroud)

在即将到来的t1之前打印

    console.log('upcoming t2',upcomingGamesList)
Run Code Online (Sandbox Code Playgroud)

但是我在这个函数中使用了await

  let upcomingGamesList = await firebase.database().ref('UpcomingGames').on('value', snapshot => {
        upcomingGamesList = snapshot.val()
        console.log('upcoming t2',upcomingGamesList)
        return upcomingGamesList
    })
Run Code Online (Sandbox Code Playgroud)

它应该等到它完成然后转到下一行

我想等到函数完成后再使用我所做的更改获取updatedList

 let …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-realtime-database

10
推荐指数
1
解决办法
1830
查看次数

如何在我的数据库中存储 Argon2 密码?

我正在尝试使用 Argon2 算法将用户密码存储在我的数据库中。

这是我通过使用它获得的:

$echo -n "password" | argon2 "smallsalt" -id -t 4 -m 18 -p 4
Type:           Argon2id
Iterations:     4
Memory:         262144 KiB
Parallelism:    4
Hash:           cb4447d91dd62b085a555e13ebcc6f04f4c666388606b2c401ddf803055f54ac
Encoded:        $argon2id$v=19$m=262144,t=4,p=4$c21hbGxzYWx0$y0RH2R3WKwhaVV4T68xvBPTGZjiGBrLEAd34AwVfVKw
1.486 seconds
Verification ok
Run Code Online (Sandbox Code Playgroud)

在这种情况下,应该在数据库中存储什么

  • 如上所示的“编码”值?
  • 如上所示的“哈希”值?
  • 两者都不是,而是另一种解决方案?

拜托,你能帮我吗?我是这个新手,我有点迷茫。

passwords hash

6
推荐指数
1
解决办法
2010
查看次数

如何实现具有超时功能的 Runnable?

我目前有一个相当简单的 SSL 服务器/客户端项目,涉及标准 Java 后端和 Android 前端。我想在与客户端发送数据后尝试读取服务器的响应。然而,我遇到了一个小问题。服务器并不总是响应,因此我必须以某种方式尝试以异步方式获取响应。(因为 read() 方法是一个阻塞方法)经过一番折腾后,我找到了一个可行的解决方案,但对我来说似乎很奇怪,就像我在做一些可能“危险”的事情。我做的第一件事是创建一个新的 Runnable 和 Thread 对象:

                    //  "reader" is of type "BufferedReader"             

                    Runnable receiveResponse = new Runnable() {
                        boolean stop = false;
                        @Override
                        public void run() {
                            try {
                                new Timer().schedule(new TimerTask() {
                                    @Override
                                    public void run() {
                                        stop = true;
                                    }
                                }, 5000);
                                char receive;
                                StringBuilder responseBuilder = new StringBuilder();
                                while (!stop && ((receive = (char) reader.read()) != END_OF_STREAM_CHAR)) {
                                    responseBuilder.append(receive);
                                }
                                // If the server responds in time I can continue …
Run Code Online (Sandbox Code Playgroud)

java asynchronous timeout runnable

6
推荐指数
1
解决办法
6187
查看次数