Giter VIP home page Giter VIP logo

fibers's Introduction

Carbon.io

Travis build status npm Version npm downloads supported node versions MIT License

Carbon.io is an application framework based on Node.js and MongoDB for building command line programs, microservices, and APIs.

With Carbon.io you can create simple, database-centric microservices with virtually no code. At the same time Carbon.io is designed to let you under the hood and allows you to write highly customized APIs much like you would with lower-level libraries such as Express.js.

Quickstart

To install:

$ npm install carbon-io

Copy the following code into service.js:

var carbon = require('carbon-io')

var o  = carbon.atom.o(module).main
var __ = carbon.fibers.__(module)

__(function() {
  module.exports = o({
    _type: carbon.carbond.Service,
    port: 8888,
    endpoints: {
      hello: o({
        _type: carbon.carbond.Endpoint,
        get: function(req) {
          return { msg: "Hello world!" }
        }
      })
    }
  })
})

This will create a Carbon.io service which will respond with "Hello world!" on the /hello endpoint. Run the service with:

$ node service

And test it using:

$ curl localhost:8888/hello

Documentation

Interested in getting started with Carbon.io? Check out our detailed documentation on the Carbon.io website.

Contributing

Interested in contributing to Carbon.io? We love to receive new contributions! There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into Carbon.io itself.

Check out our CONTRIBUTING.md for tips on how to get started!

License

MIT License

fibers's People

Contributors

gregbanks avatar tfogo avatar willshulman avatar

Watchers

 avatar  avatar  avatar  avatar

fibers's Issues

fibrous does not work with ES6 classes

Objects instantiated from an ES6 class are not able to use fibrous' .sync.

Reproduction in Node v6.9.1:

using oo:

const carbon = require('carbon-io')
const oo     = carbon.atom.oo(module)
const o      = carbon.atom.o(module)
const __     = carbon.fibers.__(module).main

__(function() {
  const Foo = oo({
    bar: function() {
      console.log('in bar')
      this.sync.baz()
    },

    baz: function() {
      console.log('in baz')
    }
  })

  const foo = o({}, Foo)
  foo.bar()
})

Output:

in bar
in baz

Using ES6 class:

const carbon = require('carbon-io')
const o      = carbon.atom.o(module)
const __     = carbon.fibers.__(module).main

__(function() {
  class Foo {
    bar() {
      console.log('in bar')
      this.sync.baz()
    }

    baz() {
      console.log('in baz')
    }
  }

  const foo = o({}, Foo)
  foo.bar()
})

Output:

in bar
TypeError: this.sync.baz is not a function
    at Foo.bar (/Users/kevinrosendahl/dev/node/sandbox/carbon-bugs/fibrous/class.js:9:17)
    at /Users/kevinrosendahl/dev/node/sandbox/carbon-bugs/fibrous/class.js:18:7
    at /Users/kevinrosendahl/dev/node/sandbox/carbon-bugs/node_modules/@carbon-io/fibers/index.js:154:20

module name clashes with laverdet/node-fibers

when flattening node_modules (npm3) var Fiber = require('fibers') resolves to the same module yielding an empty object (Fiber === {}) instead of the expected laverdet/node-fibers Fiber function.

> node debug test/All.js
< Debugger listening on port 5858
debug> . ok
break in test/All.js:1
> 1 var o  = require('atom').o(module).main
  2 var oo  = require('atom').oo(module)
  3 var _o = require('bond')._o(module)
debug> c
break in /Users/Greg/devel/repos/carbon-io/atom/node_modules/fibers/index.js:4
  2 require('fibrous')
  3
> 4 debugger
  5
  6 /*******************************************************************************
debug> require.resolve('fibers')
'/Users/Greg/devel/repos/carbon-io/carbond/node_modules/fibers/fibers.js'
debug> repl
Press Ctrl + C to leave debug repl
> Fiber
{}
debug> c
< { [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
< { [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
< { [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
< /Users/Greg/devel/repos/carbon-io/atom/node_modules/fibers/index.js:136
<   Fiber(function() {
<   ^
< TypeError: Fiber is not a function
<     at spawn (/Users/Greg/devel/repos/carbon-io/atom/node_modules/fibers/index.js:136:3)
<     at result (/Users/Greg/devel/repos/carbon-io/atom/node_modules/fibers/index.js:20:7)
<     at Atom._runMain (/Users/Greg/devel/repos/carbon-io/atom/lib/atom.js:379:7)
<     at Atom._makeObject (/Users/Greg/devel/repos/carbon-io/atom/lib/atom.js:159:16)
<     at Atom.make (/Users/Greg/devel/repos/carbon-io/atom/lib/atom.js:114:24)
<     at makeOFunc (/Users/Greg/devel/repos/carbon-io/atom/lib/atom.js:745:19)
<     at Object.<anonymous> (/Users/Greg/devel/repos/carbon-io/carbond/test/All.js:9:18)
<     at Module._compile (module.js:409:26)
<     at Object.Module._extensions..js (module.js:416:10)
<     at Module.load (module.js:343:32)
program terminated

Handling of uncaught errors in fibers

  • We devise a logging system that is more first-class and pull out of carbond
  • We have fine-grained namespace control in logging
  • Any spawned fiber that has top-level error will print by default to the logger for the fibers namespace
  • Top-level error in main will not exit program

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.