Async is the default by design. Mark Hahn expressed the reasons quite
well, so I won't reiterate them.
Sync methods look different because they *are* different.
Automatically switching from async to sync would be a violation of
Node's core principles, and a disaster.
"Node is not pretending it is blocking when it is not."
http://www.mikealrogers.com/posts/the-way-of-node.html
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
On Apr 2, 2012 3:19 AM, "Nuno Job" <nunojo...@gmail.com> wrote:
>
> >> I'm sorry if this has been discussed before, but I couldn't find anything.
>
> It has, probably 10 times a month. :) No joke!
>
Also, 'use the right tool for the job'. No one seems to get this.
I'd start killing if I ever saw a js library talking about cv.conv (or some similar continuation mechanism). I started using node because I got tired of writing a dozen languages to display a web page but along the way started liking not having an event framework (or threads) or dealing with mod_perl apache threads or fcgi and dealing with a message queue (or an event module and memcache - it works :) ) to do cool things.
Lastly, you can embed js, both seamonkey and v8 in perl (and probably other languages). You can use a queue or rpc or gearman etc to communicate between processes. Which lets you to program in anything to get the job done.
On Mon, Apr 2, 2012 at 4:20 AM, Olivier Lalonde <olal...@gmail.com> wrote:
> I believe there would be an easy way to change the status quo without
> impacting developers who chose to adhere to a strict async style. The
> solution I propose is simply a pattern for writing I/O APIs: every I/O call
> should be async unless no call back is supplied, in which case the I/O call
> should be sync and use return / throw statements instead of calling a
> callback.
Please, have a look at streamline.js
https://github.com/Sage/streamlinejs
It kind of reveres your proposed solution by giving every async
function the same callback that turns the async function into a sync
function (aka: you can write code that looks synchronous)
Short example:
var s = fs.stat(path, _)
console.log(s.size)
The underscore "_" is the callback you have to give to every async
function to turn it into a function that behaves like a synchronous
one.
I would really like to know if that might work for you.
Since Node/V8 has a rather longish startup time, this would be the
horrors for performance.
I suggest simply using streamline, your code will feel like writing Sync!
'xcept require...
The Ace lib does this, via some Fiber stuff. https://github.com/maccman/ace. I've never tried it myself though.BTW, with ruby 1.9 you can handle lots of requests per process via native Fiber support. See Sinatra::Synchrony (https://github.com/kyledrake/sinatra-synchrony) and Goliath (http://www.igvita.com/2011/03/08/goliath-non-blocking-ruby-19-web-server/). They both work very well, with pure synchronous code style.Bryan
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
This can't be stressed too often.
I wonder if the OP is still around?
I suspect that the OP is congratulating himself on a well-executed
April Fools' joke...
I suppose if the answer is zero, this is what I've also been looking
for! A syncronous javascript engine for little syncronous scripting
tasks. Not web-serving, not web-scale etc. Just some routine tasks to
calculate. It just doesn't exist yet. But honestly this is nothing
node.js should care about. Pulling together the V8 into a syncronous
script executer isn't hard, the V8 comes even with a prebuild demo
console. The hard part is establishing an alive ecosystem around that,
and I don't see that coming. As we know from other language, language
is one part, a sized standards library and solutions ecosystem is
another, and the second is difficult to pull off. Node.JS has an alive
ecosystem, and so far its simpler to workaround the async style for
that one, rather than trying to set up an alternative ecosystem.
PS: I'll just pretend it isn't an April fools...
--
The Ace lib does this, via some Fiber stuff. https://github.com/maccman/ace. I've never tried it myself though.
BTW, with ruby 1.9 you can handle lots of requests per process via native Fiber support. See Sinatra::Synchrony (https://github.com/kyledrake/sinatra-synchrony) and Goliath (http://www.igvita.com/2011/03/08/goliath-non-blocking-ruby-19-web-server/). They both work very well, with pure synchronous code style.Bryan
On Apr 1, 2012, at 7:49 PM, Olivier Lalonde wrote:
> Many times I invoke something without a callback.I didn't think about this. It seems this problem would only affect "output" functions. Not convinced it is a deal breaker yet, I'll try to come up with some workarounds.> You know that you couldn't do anything async like serve web pages, right?I'm aware of that. Writing sync web apps would imply using one process/worker by request like other popular languages do (PHP/Ruby/etc.). I think it is still interesting to use Javascript for backend development even without the async stuff.
On Monday, April 2, 2012 10:20:01 AM UTC+8, Olivier Lalonde wrote:I'm sorry if this has been discussed before, but I couldn't find anything. This a modest proposal to introduce sync APIs in Node.jsA lot of people would like to use Javascript for their web backend, but don't want to program in an async style (I believe those reasons have already been discussed at length).As it stands right now, it is practically impossible to program in Node.js in a sync style, since most core modules and native extensions only provide an async interface.I believe there would be an easy way to change the status quo without impacting developers who chose to adhere to a strict async style. The solution I propose is simply a pattern for writing I/O APIs: every I/O call should be async unless no call back is supplied, in which case the I/O call should be sync and use return / throw statements instead of calling a callback.There is probably a flaw in my reasoning since I'm probably not the first one to come up with this pattern. That being said, I think it would be an elegant way to make both async/sync fans happy while keeping all the backend JS community focused on one project rather than fragmenting the community in multiple CommonJS server implementations.Thoughts?
--
I'm sorry if this has been discussed before, but I couldn't find anything. This a modest proposal to introduce sync APIs in Node.js
A lot of people would like to use Javascript for their web backend, but don't want to program in an async style (I believe those reasons have already been discussed at length).
As it stands right now, it is practically impossible to program in Node.js in a sync style, since most core modules and native extensions only provide an async interface.
I believe there would be an easy way to change the status quo without impacting developers who chose to adhere to a strict async style. The solution I propose is simply a pattern for writing I/O APIs: every I/O call should be async unless no call back is supplied, in which case the I/O call should be sync and use return / throw statements instead of calling a callback.
There is probably a flaw in my reasoning since I'm probably not the first one to come up with this pattern. That being said, I think it would be an elegant way to make both async/sync fans happy while keeping all the backend JS community focused on one project rather than fragmenting the community in multiple CommonJS server implementations.
Thoughts?
Because Javascript > PHP === true;
but, hey, this has become a reddit post - stupidest comment generates
the most response. congrats!
Oh thats nice to see someone is putting some effort in that! Next time
I will take a serious look at SilkJS for some scripting tasks rather
than working around node.js async style, when the job at hand is
synchronous, but I want to do it in javascript nevertheless. So far it
just never has been a hugh problem to workaround.
I'm sure there is quite a place and need for syncronos
Javscript/Shell, it just has nothing to do with node.JS. I'm just not
sure the needs are large enough to develop a satisfactory ecosystem
around it.
Boring sermon and an insult. Most useless post in this thread so far.
I'm sure there is quite a place and need for syncronos
Javscript/Shell, it just has nothing to do with node.JS. I'm just not
sure the needs are large enough to develop a satisfactory ecosystem
around it.
nah, he wasn't being sarcastic. but to have the most useless post in a
pretty useless thread is a honor. thanks for the props axel :)
ps - i think some don't like hearing the truth of things they think
they'll be able to change (ie, getting more sync put into the core of
node).
But a sync-flavor io libs could nurture another set of projects. Let the community decide.
CommonJS had a much more ambitious goal of defining APIs "that handle many common application needs ... across different JavaScript interpreters and host environments" (quoting commonjs.org).I'm not proposing a fork of Node, but rather a place where developing for Node using a synchronous style could be discussed without upsetting anyone.
--
> I'm not proposing a fork of Node, but rather a place where developing for Node using a synchronous style
that's called a fork :)
awesome idea
> what's going on?
;-)