Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get value synchronously #2408

Closed
monsterooo opened this issue Sep 10, 2019 · 3 comments · Fixed by #2422
Closed

Unable to get value synchronously #2408

monsterooo opened this issue Sep 10, 2019 · 3 comments · Fixed by #2422
Labels
area/api help wanted type/enhancement Features or improvements to existing features
Milestone

Comments

@monsterooo
Copy link

Hi @Tyriar

I wrote some data using term.writeln. At the same time, I can't get the value I just set using term._core.buffer. But when I set a timer, everything works fine setTimeout(getBuffer, 3000);

I tested the demo used:
https://codesandbox.io/embed/elated-davinci-mue6q

I am very confused. Do you know why? 🤔

thank you very much!

@monsterooo
Copy link
Author

public writeBuffer: string[];

term._core.writeBuffer Is it a reliable way to use it ?

@Tyriar
Copy link
Member

Tyriar commented Sep 10, 2019

We've been discussing a method of knowing when the data was written for a while, I don't think there's an issue for it yet so let's track it in here.

#2362 has the callback for write but we might merge it in with a smaller PR before that.

@Tyriar Tyriar modified the milestones: 4.0.0, 4.1.0 Sep 10, 2019
@Tyriar Tyriar added area/api help wanted type/enhancement Features or improvements to existing features labels Sep 10, 2019
@jerch
Copy link
Member

jerch commented Sep 11, 2019

@monsterooo

I am very confused. Do you know why?

write and writeln are async methods, they get not immediately processed. The reason for this is the output, we have to process incomming data in chunks to allow the renderer to update the viewport in between.

term._core.writeBuffer Is it a reliable way to use it ?

You should not rely on term._core.writeBuffer - its not exposed via API thus may change over time. Furthermore its the buffer for incomming data, the terminal has not yet dealt with that data.

As @Tyriar wrote the plan is to add a callback to write methods (nodejs style) that gets called once the chunk was processed by the parser. With this you can promisify your code later on:

...
await new Promise(resolve => term.write('some string data', resolve));
doSomething(); // executed after the chunk was processed
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api help wanted type/enhancement Features or improvements to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants