Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GFS: API functions invoked before mongodb connection fully resolves fails #47

Open
jungkumseok opened this issue Oct 17, 2018 · 0 comments

Comments

@jungkumseok
Copy link
Collaborator

Since the global file system bootstraps asynchronously,
API calls made right after require('things-js').GFS(mongoUrl) fails because the connection is not open by then.

Example:

var gfs = require('things-js').GFS('mongodb://localhost/my-global-filesystem');
gfs.readFile('/my-test-file.json', function(err, data){
    console.log(data.toString());
});

In this example, if the mongo client is not ready by line 2 (which it won't be for most devices)
the readFile call fails.

If we were to keep the synchronous interface so that people don't have to write for example:

var gfs = require('things-js').GFS('mongodb://localhost/my-global-filesystem');
gfs.on('ready', function(){
    gfs.readFile('/my-test-file.json', function(err, data){
        console.log(data.toString());
    });
});

we would need to implement GFS as a duplex stream and maintain a request/response buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant