carbon-io / fibers

MIT License
0 stars 3 forks source link

fibrous does not work with ES6 classes #2

Closed kevindrosendahl closed 7 years ago

kevindrosendahl commented 7 years ago

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
gregbanks commented 7 years ago

see https://github.com/carbon-io/fibrous/pull/1