ipfs-shipyard / y-ipfs-connector

Y.js connector over IPFS
MIT License
58 stars 9 forks source link

Allow Promise-based encode/decode functions #9

Open larskluge opened 6 years ago

larskluge commented 6 years ago

It would be great to allow async processing of encoding and decoding of messages. For example openpgpjs encrypts and decrypts data asynchronously. The connector would need to allow to pass in async encode/decode functions via options.

Y({
  connector: 
    encode: *async* (message) => { ... }
...
larskluge commented 6 years ago

As an idea, a hacked, ugly version (for Promise usage only): https://github.com/larskluge/y-ipfs-connector/commit/0496b8bece3cec5c83b8cf2402ff57e533742465

pgte commented 6 years ago

@larskluge Looks cool! Could we also support, at the same time, providing a synchronous version of encode? (I think you could do than by wrapping encode with a promise...)

larskluge commented 6 years ago

Good thinking, I like wrapping encode into a promise, makes the code path straight forward. If I find some time soon, I'll do a PR. Cheers!