6

AFAIK meteorjs uses node-fibers, but their github page states that it is server side & v8 only (or is it not ?).

  1. How does meteorjs implement nonblocking, synchronous like api on the client side?

  2. Is it compatible with other browsers than chrome?

I would be very grateful if someone could point me to pure JS implementation of fibers, or explain how do they work (do they have own event loop?).

Any link to a github project of working client side fibers implementation will be also appreciated!

It's XMAS after all :)

g00fy
  • 4,717
  • 1
  • 30
  • 46

4 Answers4

3

The node-fibers project is a Windows-only server-side extension to Node.js, implemented in C++. You may never ever see it available in a web browser.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • 1
    That is true, but how does meteor implement fibers on the client side then? – g00fy Dec 25 '12 at 02:44
  • @g00fy it doesn't. I think you may have misinterpreted something in the documentation. – Pointy Dec 25 '12 at 03:42
  • @g00fy it may be that they do something with "web workers", but that doesn't seem to me to be very similar to threads/fibers at all. – Pointy Dec 25 '12 at 03:46
2

JavaScript is single threaded. If you wanted to implement non-blocking I/O, you would have to implement a node-style message loop and an asynchronous I/O library. By default, all client side I/O is synchronous, though Meteor and other libraries have provisions for callbacks.

Yes, Meteor's client-side implementation runs across multiple browsers besides Chrome.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
David Wihl
  • 1,491
  • 13
  • 14
  • So to be clear, how does meteor handle [Collection.find](http://docs.meteor.com/#find) on the client (witch is asynchronous) in a synchronous fashion ? You can find examples here: https://github.com/meteor/meteor/blob/master/examples/leaderboard/leaderboard.js – g00fy Dec 25 '12 at 12:45
  • 2
    Via [Reactivity](http://docs.meteor.com/#reactivity). Meteor watches for changes in the collection. When changes are detected, your template code is re-run and the resulting HTML and DOM portion are re-generated. – David Wihl Dec 26 '12 at 09:34
0

Try JSCEX (Windjs)

Wind.js is an advanced library which enable us to control flow with plain JavaScript for asynchronous programming (and more) without additional pre-compiling steps.

It worked for both server side AND client side.

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
softguy
  • 21
0

I believe on the server side, everything is purely synchronous with Meteor, thanks to MiniMongo. Thus no asynchronous callback is needed, or to be more precise, Meteor doesn't need to wait for the update callback from the server to go on to the next instruction, thanks to MiniMongo which responds synchronously.

I haven't verified everything I have just said by looking into the source code, but I can't imagine how it could work differently.

EDIT

Still haven't dived into the source code yet, but this section of the Meteor's guide seems to head the way I thought.

Alexandre Bourlier
  • 3,972
  • 4
  • 44
  • 76