Comments (6)
Yes, done
should be called after all callbacks and commands have called "next(context, data)".
The problem here is that then
should come before the data
command. The order of the console.log
messages will then be: then
, done
, then data
.
The reason data
will still appear to happen last is because it's printing after an async function (fs.readdir
) has been called. Unlike .then
, .data
doesn't expect a next(context, data)
call. This means that Osmosis has no way of knowing when the .data
callback finishes.
So done
is the last thing being called, which means Osmosis is done doing everything it needs to and now your callback code is doing what it needs to.
If you merge your .data
callback code with your .then
callback code you can use next
to tell Osmosis when your code is done. This will cause your console.log
's to happen in the order you expect.
To verify the order:
var fs = require('fs');
var osmosis = require('osmosis');
osmosis
.get('www.craigslist.org/about/sites')
.data(function(data) {
console.log('data');
})
.then(function(context, data, next) {
console.log('then');
next(context, data);
})
.done(function(){
console.log('done');
})
from node-osmosis.
My real problem is something like this
osmosis
.get('www.craigslist.org/about/sites')
.then(function(context, data, next) {
database.query(query, function(err, queryResults){
//working on queryResults
next(context, data);
});
})
.done(function(){
database.disconnect();
})
The problem is that it disconnects from the database before finishing the query which causes a database connection error in "then".
from node-osmosis.
In that case, done
shouldn't be called until then
has called next
. Obviously this must not be the case if you are still having an issue. Is your "working on queryResults" code asynchronous? this would cause next
to be called before it finished working on the query.
from node-osmosis.
Yes done
shouldn't be called until then
has called next
. But that is not the case.
This is another illustration that proves that done
is not waiting for next
. I'm setting a timeout of 5 seconds and then call next
.
var osmosis = require('osmosis');
osmosis
.get('www.google.com')
.then(function(context, data, next) {
//call next after 5 secs
setTimeout(function(){
console.log('then');
next(context, data);
},5000);
})
.done(function(){
console.log('done');
})
In that case, the output is done
and 5 seconds later it writes then
. Shouldn't done
also wait 5 seconds for next
to be called?
from node-osmosis.
There seems to be an issue when using then
immediately before done
. If you place a command between then
and done
then the code works as expected. This should be fixed in the next release.
In my test code I used the doc
command in between:
var osmosis = require('/root/node-osmosis');
osmosis
.get('www.google.com')
.then(function(context, data, next) {
//call next after 5 secs
setTimeout(function(){
console.log('then');
next(context, data);
},5000);
})
.doc()
.done(function(){
console.log('done');
})
from node-osmosis.
As of Osmosis version 0.0.9 significant stack counting changes were made and these issues should be resolved.
from node-osmosis.
Related Issues (20)
- paginate doesn't preserve the http method
- Cannot get contents of an element that contains < as text HOT 1
- figure and figcaption not supported
- Error: Invalid property for defaults:compressed HOT 8
- A question about osm map quantity
- A question about osm map quantity
- Getting "script" content seems to truncate characters after a limit HOT 2
- Worker_Threads :: Module did not self-register HOT 1
- Get elements that contains only numbers?
- How selector paginate work? HOT 8
- Add support for case insensitive wild card matching
- Build fails on NodeJS 12 HOT 3
- Use with local file HOT 1
- content of xml <link> tag not extracted? HOT 1
- [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated with node 12.16.1
- Get HTML code of element HOT 1
- not working, .data handler not called
- [HOW TO] paginate by click handler, not by link?
- How to scrape the webpage contents which takes some time to load?
- how can return values be guaranteed? HOT 4
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 node-osmosis.