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

middlewares to be async #5

Open
tunnckoCore opened this issue Jul 13, 2015 · 4 comments
Open

middlewares to be async #5

tunnckoCore opened this issue Jul 13, 2015 · 4 comments

Comments

@tunnckoCore
Copy link

Im working on tunnckoCore/benz, which i think is awesome.
Because lies on top of great libs - async-done, now-and-later and co. Allows you to pass async, callback, generator functions, passing context through them; returning and yielding promises, thunks streams; handles errors and completion of all of them.

You can look at the tests for now. Also want to mention that it is almost like bach, but bach dont have options and flexibility that i need and want. You cant pass context to all of the functions with it. With benz you can pass context and can pass result of one middleware to next if you want. Support running on parallel and on series. Just look the tests, please :)

I will try to implement also to accept sync functions. It is little bit more work cuz promises and streams looks like sync functions, so it is lil' bit tricky to determine which is stream, which is sync, which is promise. But I believe it is possible.

You can try benz now (v0.2.0) here in glob-fs instead of custom calling middlewares - its ready, just need more tests and docs that I will add today.

With the title i mean like this

var glob = require('glob-fs')()

glob.use(function notemp(file, next) {
  if (/temp/.test(file.path)) {
    file.exclude = true
  }
  next(null, file)
})

or to be possible through option like async: true?

@tunnckoCore
Copy link
Author

actually, it would be easy to determine it is glob-fs File object. I can add to checks here, just check for "if object and if object.isDotdir and object.isDotfile and then wrap it in callback style function"

edit: hm, or not so easy.

@jonschlinkert
Copy link
Member

I actually built it this way initially, but it works really well as just sync - easier to explain and maintain.

however, I agree with the underlying reason for the point you're making. I think there needs to be another check after emitting exclude and include to allow middlewares or listeners to change that decision.

fwiw, this lib is still very WIP. my guess is that it's about 50% away from the finish line. I've been using it in stuff, but only to help me figure out how to improve it... hopefully you're looking at it the same way...(?)

also, it's slow right now, but once we get to optimization we'll be able to speed it up substantially...

@tunnckoCore
Copy link
Author

hopefully you're looking at it the same way...(?)

Im thinking that it should be just thin wrapper with fast defaults - custom readers, custom iterators. Are you thinking to expose custom readers and iterators?

my guess is that it's about 50% away from the finish line.

I dont think you should do so much, lol. For me it is almost done, except custom readers, iterators and improve middlewares.

see last two comments #2 (comment)

@jonschlinkert
Copy link
Member

I dont think you should do so much, lol

Usually I tend to do everything in one lib until I get it right. then I break things out. it's just my preference. I guess I'm conservative and would rather make sure we have the right conventions first

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