question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promisifying Level, issue with encodeLtgt?

See original GitHub issue

Hey guys,

Not sure if this really is the proper place to ask, but I’ll try anyway (unless you guys have a Discord or Slack server).

I’m attempting to promisify level in my own way - the existing then-level isn’t actually working, a few issues pushed me to work on my own version, which also happens to support node 8 native promisifying using the util module.

The full code is gisted here. The issue I have specifically is when attempting to create a createKeyStream.

Code:

const lp = new LevelPromise('hallo');

const test = async() => {
  await lp.put('hallo', 'hehe');
  const rv = await lp.get('hallo');
  console.log(rv);
  
  const output = [];
  lp.createKeyStream()
    .on("data", key => lp.get(key).then(d => output.push(JSON.parse(d))))
    .on("end", () => console.log(output));
  
  //await lp.close();
  //lp.destroy();
}

test();

Resulting Error:

Uncaught Promise Error:  TypeError: Cannot read property 'encodeLtgt' of undefined
    at LevelPromise.LevelUP.readStream.LevelUP.createReadStream (/root/level-promise/node_modules/levelup/lib/levelup.js:323:24)
    at LevelPromise.LevelUP.keyStream.LevelUP.createKeyStream (/root/level-promise/node_modules/levelup/lib/levelup.js:336:15)
    at test (/root/level-promise/index.js:61:6)
    at <anonymous>

I’m not having this issue without the promisify stuff, createKeyStream works correctly.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ralphtheninjacommented, Aug 18, 2017
this[key] = (...args) => this.level[key](...args);

Now you’re binding 😉 This should be the same as doing

this[key] = this.level[key].bind(this.level);
0reactions
vweeverscommented, Aug 18, 2017

However, vmweevers put me on the right track: this[key] = prototype[key]; doesn’t work for… honestly I’m not exactly sure, the exact inner workings of javascript are sometimes a little beyond me.

Credit goes to @ralphtheninja 💘

@eslachance The reason that this[key] = prototype[key] doesn’t work is because in JavaScript the value of this is determined by how a function is called.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promisification - The Modern JavaScript Tutorial
“Promisification” is a long word for a simple transformation. It's the conversion of a function that accepts a callback into a function that ......
Read more >
Promisify of method without last argument callback ... - GitHub
Currently, our documentation states: promisify() assumes that original is a function taking a callback as its final argument in all cases, ...
Read more >
How To Turn SetTimeout and SetInterval Into Promises
How to promisify setTimeout. Take this code: const foo = () => { setTimeout(() => { console.log('Callback based stuff ...
Read more >
How to Write Your Own Promisify Function from Scratch
Introduction In this article, you will learn how to write your own promisify function from scratch. Promisification helps in dealing with ...
Read more >
Promisifying Your Node Callback Functions: Grouparoo Blog
The Grouparoo application is written in JavaScript (Node). It uses the modern promise-based pattern ( async / await ) for reading and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found