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

Already on GitHub? Sign in to your account

ac._dispatch behaves differently #523

Closed
dmorilha opened this Issue Sep 18, 2012 · 7 comments

Comments

Projects
None yet
3 participants
Contributor

dmorilha commented Sep 18, 2012

for (var i = 0; i < 2; i++) {
  ac._dispatch(command, adapter)
  console.log('i', i);
}

first run:

INFO mojito-dispatcher: Dispatching an instance of 'a/index' with the modules: [mojito-perf, mojito, mojito-scheduler-addon, a, mojito-config-addon, yui-base, json-stringify, oop, event-custom-base, mojito-view-renderer, array-extras, mojito-util, mojito-output-adapter-addon, querystring-parse, querystring-stringify, querystring-stringify-simple, mojito-route-maker, mojito-url-addon, mojito-assets-addon, mojito-http-addon, mojito-cookie-addon, mojito-params-addon, mojito-composite-addon, mojito-action-context, mojito-controller-context, mojito-resource-store-adapter, intl-base, event-custom-complex, intl, mojito-dispatcher, mojito-hb, mojito-mu]
INFO mojito-dispatcher: Creating controller context
INFO mojito-dispatcher: caching controller context: yui_3_5_1_2_4_1347991477957_4970
i 0
i 1
INFO mojito-dispatcher: Dispatching an instance of 'b_1/index' with the modules: [mojito-perf, mojito, b, mojito-config-addon, yui-base, json-stringify, oop, event-custom-base, mojito-view-renderer, array-extras, mojito-util, mojito-output-adapter-addon, querystring-parse, querystring-stringify, querystring-stringify-simple, mojito-route-maker, mojito-url-addon, mojito-assets-addon, mojito-http-addon, mojito-cookie-addon, mojito-params-addon, mojito-composite-addon, mojito-action-context, mojito-controller-context, mojito-resource-store-adapter, intl-base, event-custom-complex, intl, mojito-dispatcher, mojito-hb, mojito-mu]
INFO mojito-dispatcher: Creating controller context
INFO mojito-dispatcher: caching controller context: yui_3_5_1_2_4_1347991477957_5056
INFO mojito-dispatcher: Dispatching an instance of 'b_2/index' with the modules: [mojito-perf, mojito, b, mojito-config-addon, yui-base, json-stringify, oop, event-custom-base, mojito-view-renderer, array-extras, mojito-util, mojito-output-adapter-addon, querystring-parse, querystring-stringify, querystring-stringify-simple, mojito-route-maker, mojito-url-addon, mojito-assets-addon, mojito-http-addon, mojito-cookie-addon, mojito-params-addon, mojito-composite-addon, mojito-action-context, mojito-controller-context, mojito-resource-store-adapter, intl-base, event-custom-complex, intl, mojito-dispatcher, mojito-hb, mojito-mu]
INFO mojito-dispatcher: Creating controller context
INFO mojito-dispatcher: caching controller context: yui_3_5_1_2_4_1347991477957_5114

second run:
INFO mojito-dispatcher: Dispatching an instance of 'a/index' with the modules: [mojito-perf, mojito, mojito-scheduler-addon, a, mojito-config-addon, yui-base, json-stringify, oop, event-custom-base, mojito-view-renderer, array-extras, mojito-util, mojito-output-adapter-addon, querystring-parse, querystring-stringify, querystring-stringify-simple, mojito-route-maker, mojito-url-addon, mojito-assets-addon, mojito-http-addon, mojito-cookie-addon, mojito-params-addon, mojito-composite-addon, mojito-action-context, mojito-controller-context, mojito-resource-store-adapter, intl-base, event-custom-complex, intl, mojito-dispatcher, mojito-hb, mojito-mu]
INFO mojito-dispatcher: Creating controller context
INFO mojito-dispatcher: caching controller context: yui_3_5_1_2_4_1347991477957_5229
INFO mojito-dispatcher: Dispatching an instance of 'b_3/index' with the modules: [mojito-perf, mojito, b, mojito-config-addon, yui-base, json-stringify, oop, event-custom-base, mojito-view-renderer, array-extras, mojito-util, mojito-output-adapter-addon, querystring-parse, querystring-stringify, querystring-stringify-simple, mojito-route-maker, mojito-url-addon, mojito-assets-addon, mojito-http-addon, mojito-cookie-addon, mojito-params-addon, mojito-composite-addon, mojito-action-context, mojito-controller-context, mojito-resource-store-adapter, intl-base, event-custom-complex, intl, mojito-dispatcher, mojito-hb, mojito-mu]
INFO mojito-dispatcher: Creating controller context
INFO mojito-dispatcher: caching controller context: yui_3_5_1_2_4_1347991477957_5300
i 0
INFO mojito-dispatcher: Dispatching an instance of 'b_4/index' with the modules: [mojito-perf, mojito, b, mojito-config-addon, yui-base, json-stringify, oop, event-custom-base, mojito-view-renderer, array-extras, mojito-util, mojito-output-adapter-addon, querystring-parse, querystring-stringify, querystring-stringify-simple, mojito-route-maker, mojito-url-addon, mojito-assets-addon, mojito-http-addon, mojito-cookie-addon, mojito-params-addon, mojito-composite-addon, mojito-action-context, mojito-controller-context, mojito-resource-store-adapter, intl-base, event-custom-complex, intl, mojito-dispatcher, mojito-hb, mojito-mu]
INFO mojito-dispatcher: Creating controller context
INFO mojito-dispatcher: caching controller context: yui_3_5_1_2_4_1347991477957_5371
i 1

Collaborator

caridy commented Sep 18, 2012

What version of mojito?

Contributor

dmorilha commented Sep 18, 2012

0.4.2 but I already checked that on previous versions...

Collaborator

caridy commented Jan 29, 2013

@dmorilha, is this still an issue in 0.5.x?

Contributor

dmorilha commented Mar 7, 2013

@caridy @jimenez yes, still an issue on 0.5.4. Sorry for the huge delay, I usually don't see public github notifications.

Collaborator

caridy commented Mar 7, 2013

Yes, and it makes sense. The reason for this behavior is the instance expansion process. _dispatch (which is an internal API that you should not be using) will use dispatcher.dispatch under the hood, which uses store.expandInstance(command.instance, command.context, callbackWhenInstanceIsReady). And the expandInstance method could be async or sync depending on the state of the internal cache. If the instance is already expanded, it runs in sync mode, which is what happen during your second pass.

@caridy caridy closed this Mar 7, 2013

Contributor

jlecomte commented Apr 10, 2013

A method should not be sometimes synchronous and sometimes asynchronous if it does not support a callback function as a parameter. That is the only way to abstract the nature of the execution of a routine.

Yes, we are calling an internal API and there are good reasons why we are doing that. We would like to have the _dispatch method support a callback function as argument so that our code will work on the first run as well as any subsequent runs! Thanks.

Collaborator

caridy commented Apr 10, 2013

@jlecomte let me rephrase my initial statement "And the expandInstance method could be async or sync depending on the state of the internal cache.", I should have said "And the expandInstance method will call the callback method in an async or sync way, depending on the state of the internal cache."

I'm not very familiar with the reasons why ac._dispatch, and the subsequence processes were designed that way, but one this is clear for me, ac._dispatch does support a callback, not in the tradicional way, but thru the adapter (second argument). adapter.error and adapter.done are the two posible callbacks. Now, if you need a callback to tell you about the progress of the operation, saying, when the instance was expanded, when the action is finished, when the render is started, etc, we will have to evaluate it. I will like to understand more about your use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment