hypercore-protocol / hypercore-next

Hypercore 10 is an append only log with multi-writer primitives built in.
MIT License
150 stars 15 forks source link

Refactor session open flow #63

Closed andrewosh closed 2 years ago

andrewosh commented 2 years ago

The current session open flow will not support passing sessions preload or valueEncoding options.

With this new approach, the storage opening is extracted into a _openCapabilities method that's only called by the first session. All sessions are opened with a _openSession method, which waits on the capabilities opening Promise.

As part of this, I also cleaned up some of the opening flow and added another session test. The session tests were making assumptions about sessions that break parity with normal Hypercore:

  1. session.writable should only be readable after session.ready() resolves
  2. core.session() should not synchronously throw on errors that would typically be thrown in core.ready()

This PR changes those behaviors for consistency.

One final thing: corestore@next has been depending on the postload option, which we didn't think through. A better approach is to have a hidden option _preready for the Corestore use-case, as nobody else should need this feature (it's very opaque).