Comments (6)
What did you expect to get by doing that? I'm missing the functionality
from co.
Assume foo has some other properties in it that are thunks to get later values. The Date objects in there will get reset in the yield.
Here's a more verbose example;
var assert = require('assert')
var co = require('co')
co(function* () {
var foo = {
other: function (done) {
setTimeout(function () {
done(null, 'delayed value')
}, 100)
},
now: new Date
}
var bar = yield foo
assert(bar.other === 'delayed value')
assert(foo.now.getTime() === bar.now.getTime())
})()
foo.now and bar.now should contain the same Date object, so calling getTime() on either should return the same value. This is not the case currently. foo.now.getTime() will be equal to the time the foo object was created, while bar.now.getTime() will be equal to the time the yield resolved. The value gets reset.
from co.
I was looking at the tests and understand your issue:
it('should ignore non-thunkable properties', function(done){
co(function *(){
var res = yield {
name: { first: 'tobi' },
age: 2,
address: read('index.js', 'utf8')
};
res.name.should.eql({ first: 'tobi' });
res.age.should.equal(2);
res.address.should.include('exports');
})(done);
})
from co.
Yeah, that stuff works fine. It's the Date object specifically that doesn't work. I'm guessing co needs some extra stuff to detect instances of things and not run them through the recursive object yielding stuff or something. Not sure exactly how that'd work.
from co.
The behavior is correct, in your example foo.now
and bar.now
have the same value.
Because Date
is an object
and not a primitive, it goes through objectToThunk
, and a new Date object is created, so the assertion is invalid.
function objectToThunk(obj){
var ctx = this;
return function(done){
var keys = Object.keys(obj);
var pending = keys.length;
var results = new obj.constructor(); <-- here is created a new Date object
var finished;
...
I don't know if this is an issue, because the desired functionality is correct.
from co.
Breaking any object that normally takes arguments to initialize is correct behaviour?
It should probably do a obj.constructor === Object check or something before running that.
from co.
Related Issues (20)
- The co's then-function called before than thunkify function HOT 2
- Process yield undefined HOT 7
- Why can not choose Promise implement lib
- Using co in the browser HOT 1
- try/catch doesn't work HOT 1
- Set a sleep interval between each resolve? HOT 3
- there is something unsuitable about isGenerator and isObject function HOT 2
- Add `.finally` HOT 5
- Yielding to array of promises behavior
- isGeneratorFunction will return true when the obj is a generator
- Confused about the doc on yield generator
- Does it make sense to use control flow in the project's description?
- Promises still in the event Loop
- .catch and .then are both called when an exception is thrown HOT 2
- Add streams into yieldable list HOT 2
- why the objectToPromise function so complex ?
- Added type for `co`
- who can answer me ? what the 'co''s full name? thks! HOT 2
- .
- Why not support 'import'? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from co.