Ind.ie is now Small Technology Foundation.
Commit d7ca49e4 authored by Aral Balkan's avatar Aral Balkan

Fix callback on onwrite handler; add simple append test

parent 8c3688a9
......@@ -99,11 +99,42 @@ function generateKeys() {
onwrite: (index, data, peer, cb) => {
console.log(`Feed: [onWrite] index = ${index}, peer = ${peer}, data:`)
console.log(data)
cb()
}
})
feed.on('ready', () => {
console.log('Feed: [Ready]')
console.log(`Feed writeable? ${feed.writable}`)
const stream = feed.createReadStream({live:true})
stream.on('data', x => console.log(x))
//
// TEST
//
const NUMBER_TO_APPEND = 1
let counter = 0
Date.prototype.getUnixTime = function() { return this.getTime()/1000|0 };
const updateInterval = setInterval(() => {
counter++
if (counter === NUMBER_TO_APPEND) {
console.log(`Reached max number of items to append (${NUMBER_TO_APPEND}). Will not add any more.`)
clearInterval(updateInterval)
}
const key = (new Date()).getUnixTime()
const value = Math.random()*1000000000000000000 // simple random number
let obj = {}
obj[key] = value
feed.append(obj, (error, sequence) => {
console.log('Append callback')
console.log('Error', error)
console.log('Sequence', sequence)
})
}, 1000)
})
feed.on('error', (error) => {
......@@ -130,9 +161,6 @@ function generateKeys() {
console.log('Feed close')
})
// TEST
feed.append({'a': 'test'})
// Display the keys.
publicSigningKeyTextField.value = to_hex(keys.publicSignKey)
privateSigningKeyTextArea.value = to_hex(keys.secretSignKey)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment