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

non-stream method stock.get() never finishes when object not existing #44

Open
jkropf opened this issue Jun 14, 2024 · 0 comments
Open

Comments

@jkropf
Copy link

jkropf commented Jun 14, 2024

First of all, many thanks for the package! It satisfies my needs in caching media files (images and audio) in a app which needs to run on multiple platforms including web.

However, when I request a file from the cache using an indexed DB, the code

Uint8List data = await stock.get(path);

never finishes, even the data gets fetched and stored in the database successfully. The writer method for the database finishes and returns the data:

Future<Uint8List> writeFile(path, data) async {
   var txn = db.transaction(storeName, "readwrite");
   var store = txn.objectStore(storeName);
   await store.put(data, path);
   log.d("writing finished. waiting for completion.");
   await txn.completed;
   log.d("writing data to database completed");
   return data;
}

When the data is already cached and existing in the database, everything works as expected.

Here is the initialization of the stock:

final futureFetcher = Fetcher.ofFuture<String, Uint8List>(
          (path) => _apiService.getFile(path),
    );

final sourceOfTruth = SourceOfTruth<String, Uint8List>(
        reader: (path) => _database!.getFile(path),
        writer: (path, data) => _database!.writeFile(path, data!),
       );

    // Create Stock
    stock = Stock<String, Uint8List>(
        fetcher: futureFetcher,
       sourceOfTruth: sourceOfTruth,
    );

Kind regards,
Johannes

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