Skip to content

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

Description

@jungkumseok

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions