1

I have the folowing constructor...

@Inject
public EditorPresenter(final EventBus eventBus, final MyView view, final Provider<DataProvider> provider) {

    DataProvider provider = provider.get();
    provider.getInitData().fire(new Receiver<List<DataElement>>() {

        @Override
        public void onSuccess(List<DataElement> response) {
            LOG.info("seting feed types to {}", response);
            EditorPresenter.this.data = response;
        }
    });
}

This constructor sets the class field data to the values returned in the request factory call.

The problem is this data requires a call to the server and is thus asynchronous.

And this field needs to be set when the constructor returns as other objects/beans depend on it (I'm having subsequent errors that depend on data being initalised).

What is the most efficient and light weight way of handling this scenario with Gin?

I'm hoping that there is something built into GIN that handles this scenario gracefully.

Michael Wiles
  • 20,902
  • 18
  • 71
  • 101

3 Answers3

0

GQuery Promise solves this kind of situations:

Something like:

public void yourMethod(....) {
  ....

  getDataFromServer(provider).then(processData)
  .done(new Function() { public void f(){
    continueYourFlow();
  }})
  .fail(new Function() { public void f(){
    handleError();
  }});
}

  protected Promise getDataFromServer(final Provider<DataProvider> provider) {
    return new PromiseRF(provider.getInitData());
  }

  Function proccessData = new Function() { public void f() {
    List<DataElement> data = arguments(0);
    //do something with your data
  }};

should work. If not, just ask!

apanizo
  • 628
  • 5
  • 11
0

There is something wrong in your approach. You shouldn't hold all your application waiting for server.

If I understand, some data from server is required before client is initialized. Maybe you should put them in your host page? Or move initialization of presenters to other methods and execute these methods by events.

0

It might be best to not initialize the rest of your app yet. I'm not sure how your initialization is laid out, but I would not initialize anymore after you inject the instance of your EditorPresenter class.

When your onSuccess call gets triggered, fire an event or call a method that picks up where you would have left off. If you think it will be a while you could throw up a wait screen or some such.

britter
  • 141
  • 2
  • 11