2

there are several js libraries available for flow control.

though when working with the closure compiler the ones i looked at yet do not work well with the compiler in advanced mode.

is there any closure compatible flow control library? I am mostly interested in waiting on multiple results without complicating the code more than necessary.

What i want to archive is to reduce loading time on user actions. For one action of the user multiple requests have to be done to the backend. To keep the code maintainable, at the moment, i do one request at a time and handle potential errors after each step.

What i want to archive is that i can just fire nondepended requests together without complicating the error handling more than necessary.

I like the syntax of flow js:

var auth = flow.define(
    function(username, password) {

        sys.puts("trying " + username + ", " + password);

        this.password = password;
        keystore.get('userId:' + username, this);

    },function(err, userId) {

        keystore.get('user:' + userId + ':password', this);

    },function(err, passwordInDb) {

        if (passwordInDb == this.password) {
            sys.puts("Authenticated!");
        }
        else {
            sys.puts("Failed Authentication!");
        }
    }
)

It also allows to spawn multiple async operations and collect them. Though if you need any state between callbacks the state is stored like "this.password" above. as the containing scope is not typed the closure compiler will not be able to rename it consistently (from my understanding) when in ADVANCED mode.

So i need an alternative which has a typed container object that is pushed as a parameter (or this) through each function.

marco
  • 41
  • 3
  • You should add some clarification: what kind of flow control are you talking about? Can you give some example flow control libraries that don't work? – John Sep 19 '12 at 21:35
  • thanks ... tried to clarify on the example of flow.js -- which seems to be quite nice when comparing size and functionality. – marco Sep 19 '12 at 21:46

4 Answers4

1

Can you use goog.async.Deferred from Closure Library? It manage async and sync workflow.

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
0

Generally, you can use any library with Closure Compiler's advanced mode by creating an extern file for the library and loading the code separately (or concatenating the library after compilation of your code).

John
  • 5,443
  • 15
  • 21
  • yes, the but even if the library compiles fine, the resulting codestyle when using the library will not always work without complication. I've added an example to clarify. – marco Sep 19 '12 at 21:49
  • I agree, this approach would not be useful here. – John Sep 19 '12 at 22:00
0

Ok i've found a solution.

When i create a typed container object and pass it to each of the functions with goog.bind it works.

marco
  • 41
  • 3
0

A very tiny flow control lib for Closure Library i've written is ready.js.

As per the description:

Watches over multiple async operations and triggers listeners when all or some are complete.

It's worth a look

thanpolas
  • 848
  • 1
  • 8
  • 20