Last active
August 24, 2019 16:23
-
-
Save vasco-santos/748c49fe07a2b1d2fa85f25a093501bf to your computer and use it in GitHub Desktop.
Adapter for noise [https://github.com/ethberlinzwei/Bounties/issues/17]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const promiseToCallback = require('promise-to-callback') | |
const toPull = require('async-iterator-to-pull-stream') | |
const encrypt = async (localId, conn, remoteId) => { | |
// TODO implementation | |
// ... | |
pull( | |
conn, | |
toPull.duplex(handshake(state, finish)), | |
conn | |
) | |
// ... | |
} | |
module.exports = { | |
tag: '...', | |
encrypt (localId, conn, remoteId, callback) { | |
promiseToCallback(encrypt(localId, conn, remoteId))(callback) | |
}, | |
encryptAsync: encrypt | |
} |
Author
vasco-santos
commented
Aug 24, 2019
'use strict'
const pipe = require('it-pipe')
const mainIniator = async () => {
const numberSource = () => [1, 2, 3, 4, 5]
const collect = async (source) => {
for await (const val of source) {
console.log('val', val)
}
}
const connection = {
sink: collect,
source: numberSource()
}
await pipe(['first message'], connection)
await pipe(
connection,
function transform(source) {
return (async function* () { // A generator is async iterable
let step = 1
for await (const val of source) {
if (step % 2 === 0) {
yield val * 2
} else {
yield step
}
step += 1
}
})()
},
connection)
}
const mainReceiver = async () => {
const numberSource = () => [10, 20, 30, 40, 50]
const collect = async (source) => {
for await (const val of source) {
console.log('val', val)
}
}
const connection = {
sink: collect,
source: numberSource()
}
await pipe(
connection,
function transform(source) {
return (async function* () { // A generator is async iterable
let step = 0
for await (const val of source) {
if (step % 2 === 0) {
yield val * 2
} else {
yield step
}
step += 1
}
})()
},
connection)
}
mainIniator()
mainReceiver()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment