Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果不确定调用顺序,该如何按序触发,是否有可能实现 #3

Closed
bigbigbig opened this issue Sep 29, 2021 · 5 comments

Comments

@bigbigbig
Copy link

假如我的页面有很多弹窗,假如所有弹窗都有一个随机时间的弹出,但是我不希望这些弹窗一起弹出,当一个弹窗a触发了弹出之后,另一个弹窗b到达弹出时间也不弹出,等到a关闭时再弹出,但是a和b我事先并不知道弹出顺序,有可能a先弹出,有可能b先弹出,我使用这个库的时候,发现我没法在代码运行时,动态的去加入trigger,而是需要我事先在builder创建时候加入,这个问题是否有实现的可能

@iostyle
Copy link
Owner

iostyle commented Oct 15, 2021

假如我的页面有很多弹窗,假如所有弹窗都有一个随机时间的弹出,但是我不希望这些弹窗一起弹出,当一个弹窗a触发了弹出之后,另一个弹窗b到达弹出时间也不弹出,等到a关闭时再弹出,但是a和b我事先并不知道弹出顺序,有可能a先弹出,有可能b先弹出,我使用这个库的时候,发现我没法在代码运行时,动态的去加入trigger,而是需要我事先在builder创建时候加入,这个问题是否有实现的可能

抱歉看到这个问题有点晚
首先这个项目的宗旨是连续有序的触发器,你的这个需求我建议你fork一个分支出来进行修改
建议的思路是可以在attach方法处判断当前节点不在队列内加入到队列里面即可

你先尝试一下,有问题我们再沟通

@iostyle iostyle closed this as completed Oct 15, 2021
@iostyle
Copy link
Owner

iostyle commented Oct 15, 2021

image

@iostyle
Copy link
Owner

iostyle commented Oct 15, 2021

    //绑定执行 为Java代码提供的重载
    @Synchronized
    fun attach(id: String, strike: Trigger.Strike) {
        attach(id, strike, false)
    }

    //绑定执行
    @Synchronized
    fun attach(id: String, strike: Trigger.Strike, adjustAttach: Boolean = false) {
        if (debugMode) log("ContinuousTrigger attach ${id}")

        //阻塞唤醒
        if (tryWakeUp(id, strike)) {
            if (debugMode) log("ContinuousTrigger blockNode wakeup")
        } else if (triggerList?.isEmpty() == false) {
            triggerList?.forEach {
                if (it.id == id) {
                    it.strike = strike
                    return
                }
            }
            /**
             * 代码走到这里代表你attach的事件没有被绑定或者已经超时被跳过
             */
            if (adjustAttach)
                adjustAttach(id, strike)
        } else {
            /**
             * 代码走到这里意味着所有的事件都已经超时
             */
            if (adjustAttach)
                adjustAttach(id, strike)
        }
    }

    /**
     * 灵活绑定 内部调用用于已超时的补充或者id未注册场景
     * 外部使用的话如果不需要顺序控制则不需要注册 直接调用adjustAttach即可按需排队阻塞显示
     */
    @Synchronized
    fun adjustAttach(id: String, strike: Trigger.Strike, chokeMode: Boolean = false) {
        register(Trigger().also {
            it.id = id
            it.chokeMode = chokeMode
            it.strike = strike
        })
    }

@iostyle
Copy link
Owner

iostyle commented Oct 15, 2021

@bigbigbig 已经更新了1.0.6版本 欢迎尝鲜

@guominfang
Copy link

这个问题处理了吗?

需求,同时检查APP更新和数据库更新,根据接口返回,是否弹出dialog提示,如下图接入方式,代码不工作

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants