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

Run signal of IOs #8

Open
rogeriochaves opened this issue Mar 7, 2016 · 2 comments
Open

Run signal of IOs #8

rogeriochaves opened this issue Mar 7, 2016 · 2 comments

Comments

@rogeriochaves
Copy link

Hello,

So, I'm using elm-console to run elm-test tests. But I have the case where I'm trying to test signals and effects.

Long story short, I manage to end up with a Signal Test, and I need to map those tests to consoleRunner then Console.run to run the tests each time a new test comes from the signal.

But Console.run takes an IO and returns a Signal of Tasks, so I would end up with Signal (Signal (Task.Task x ())), and Signal of Signals aren't allowed in elm.

My workaround to solve this was creating this library: signal-concat-map that allows me to concatMap signals, by using native modules.

You can check out the final code of the TestRunner here.

I wouldn't need this if there was a way to run signals of IO, like this:

Console.runSignal : Signal IO -> Signal (Task x ())

Is this possible in elm-console?

Thanks!

@laszlopandy
Copy link
Owner

The IO type is a chain of operations which doesn't ever idle. It is either actively processing an IO operation, or blocking on waiting for user input. This is similar to how you would write an old console application in C, as opposed to JS apps which have a mainloop and remain idle until the next event comes.

If you look at how IO is implemented, every operation (except exit) has a mandatory next operation (see the comment on this line). So you cannot just say run one IO and then go idle. In IO apps there is no concept of idle. You either perform the next operation or exit.

Can I ask how you got to a Signal Test in the first place? How do you indicate which is the last test, so you know you are done and can exit?

@rogeriochaves
Copy link
Author

@laszlopandy so, I was trying to test an effect that sends an action to a mailbox, and I want to map over that mailbox signal and make the expectation there. That's why I end up with a Signal Test.

Right now, the way it knows when it's "the last test" is that it starts running the specs, but if another Signal Test value comes along before the consoleRunner reaches its exit command, the runner is interrupted, and starts running the new tests. If no other signal comes then it exists successfully.

This could be replaced with a waiting period maybe. Wait for X seconds then executes all tests on the signal.

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

2 participants