Coder Social home page Coder Social logo

[Query]: About switch work-thread about agera HOT 10 CLOSED

google avatar google commented on May 22, 2024
[Query]: About switch work-thread

from agera.

Comments (10)

likai79511 avatar likai79511 commented on May 22, 2024

Otherwise,I have a additation question:
I create a repository and while add some action on it, before the .compile() Agera will automatic add/implementation notifyIf and check old value and new value to check if need update.,right?
now,I want to execute their all directives only if observe()'s observable send a dispatch(). but now,I add a updatable while their directives will be execute,it's not my expect. I try to add golazy() and trigger get() to execute, and met other problem,if add golazy() and after can not add goto().. so still can't resolve problem.
I expect: only .observe(mOb) 's mOb to send dispatch() their all directives can be execute.
no expect: only add updatable their all directives can be execute.
please give me some help,thanks

from agera.

likai79511 avatar likai79511 commented on May 22, 2024

Connect above,
Because I need add some action on repository,so only use .repositoryWithInitialValue() not ..mutableRepository(). actually is CompiledRepository, and CompiledRepository extends BaseObservable and implementation ptotect method:observableActivated(), so just add Updatebale will be start.

from agera.

maxtroy avatar maxtroy commented on May 22, 2024

I can't fully understand your follow-up questions. Feel free to use Chinese and I'll translate your questions to English and then answer them in both languages.

About main-thread executor: you don't need to use a main-thread executor in the flow, unless for some reason you have to go back to the main thread to retrieve more data for your computation. When you've finished producing the value in the background thread, all observers will react on the main thread (if they were registered on the main thread).

from agera.

likai79511 avatar likai79511 commented on May 22, 2024

Sorry,my english is poor,I will be careful.
About main-thread executor: I know the updatable will be runing on registered thread when receive notify. For example: I create a repository and include some actions on it, such as getFrom、transfer、mergin.. ,I want to runing getFrom on non-mainThread,for this point,I can use goto(Executor) to do it, but if I do it,the rest of flows both runing on this thread.,now I want to running transfer on main-thread, how to do it, how to switch main-thread. and note: I have no use goLazy() so only all actions finished the updatable can be runing.

from agera.

likai79511 avatar likai79511 commented on May 22, 2024

About another problem:
I create a repository use mRep = Repositories.repositoryWithInitialValue(null), and then observe a Observable use .observe(mOb). and add some actions after it,such as getGrom,thransfter etc.
I expect: mRep's all actions start execute only when mOb to do dispatch() rather than mRep.addUpdatable(this).
But I find mRep's actions will be start as long as execute mRep.addUpdatable(this), actually Repositories.repositoryWithInitialValue() will be create a 'CompiledRepository' and this class also implementation 'observableActivated()',so I don't know how to handle this problem. and goLazy() can't match my requirement,so can't use this.

from agera.

sfcecy7i avatar sfcecy7i commented on May 22, 2024

private object MainThreadExecutor : Executor {
private val handler = Handler(Looper.getMainLooper())
override fun execute(command: Runnable?) {
handler.post(command)
}
}

from agera.

 avatar commented on May 22, 2024

Thanks @sfcecy7i !

On your second issue, the life cycle is described here. Basically, by design, and shouldn't be avoided. I think you need to reassess your design if this is what you need.
Also, you can't create a repository with null, you'll have to have a concrete default value

from agera.

likai79511 avatar likai79511 commented on May 22, 2024

@sfcecy7i @ernstsson Thanks!

from agera.

maxtroy avatar maxtroy commented on May 22, 2024

@likai79511, you can still hack the system into your will, using creativity :)

AtomicBoolean activatedOnce = new AtomicBoolean(false);
Repository<V> repository = repositoryWithInitialValue(initialValue)
    .observe(obs)
    .onUpdatesPer...
    .check(_ -> activatedOnce.getAndSet(true)).orSkip() // creativity
    .getFrom.....
    ......
    .compile();

// in use site; suppose the repository will only have one updatable at most:
activatedOnce.set(false);
repository.addUpdatable(updatable);

repository.removeUpdatable(updatable);

from agera.

likai79511 avatar likai79511 commented on May 22, 2024

@maxtroy Thanks. use check() to skip the rest of flows is very simply way and solve my problem.
I even thought to that override repositoryWithInitialValue and extends CompiledRepository.

from agera.

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.