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

stream.Writable.finalの動作確認 #7

Open
takashiski opened this issue Nov 20, 2019 · 4 comments
Open

stream.Writable.finalの動作確認 #7

takashiski opened this issue Nov 20, 2019 · 4 comments

Comments

@takashiski
Copy link

Haxe4から予約語として final が追加されたため、nativeタグなどで別名を定義する必要が発生しました。

https://github.com/HaxeFoundation/hxnodejs/blob/master/src/js/node/stream/Writable.hx#L250
https://github.com/HaxeFoundation/hxnodejs/blob/master/src/js/node/stream/Writable.hx#L331

しかし、構造体の中ではnativeタグが使えません。
そのため、@terurouによって吸収するabstructが作成されました。

https://github.com/HaxeFoundation/hxnodejs/blob/master/src/js/node/stream/Writable.hx#L219
https://github.com/HaxeFoundation/hxnodejs/blob/master/src/js/node/stream/Writable.hx#L342-L355

このabstructで_finalが呼ばれるかどうかを確認する必要があります。

@takashiski
Copy link
Author

finalをどう呼べばいいのか知らないのでそれっぽいコードをnodejsで書いたけどこの時点でfinalが呼ばれていない...
https://gist.github.com/takashiski/2c98b0114a4bde6b541f153311929039

https://nodejs.org/api/stream.html#stream_writable_final_callback

@terurou
Copy link
Member

terurou commented Nov 21, 2019

@ahuglajbclajep Node.js APIの使い方を教えてあげてください

@ahuglajbclajep
Copy link

Decoding buffers in a Writable Stream を参考に書いてみました。
最小の例はこんな感じだと思います。

const { Writable } = require("stream");

class MyWritable extends Writable {
  constructor() {
    super();
    this.data = "";
  }

  _write(chunk, encoding, callback) {
    console.log(`_write called and written "${chunk}"`);
    this.data += chunk;
    callback();
  }
  _final(callback) {
    console.log("_final called");
    callback();
  }
}

const w = new MyWritable();
w.write("hello, ");
w.end("world!");
console.log(w.data);

@takashiski
Copy link
Author

ありがとうございます!
C++のあれと同じ感じですかね。

ほぼ丸っと使わせていただいて、finalが呼ばれていることが確認できました 🙌
https://gist.github.com/takashiski/50af27a05eb1512797f2dfb618bd3e34

確認して頂いて、よさそうなら締めていただけますか?@terurou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants