GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||
GeezerVison is showing github.com — fs: support abortsignal in writeFile by benjamingr · Pull Request #35993 · nodejs/node Conversation
Member
Now that #35911 is landed the next suggestion in #35877 by @mcollina was fs.writeFile (here #35877 (comment) ) - so I am going over the suggestions one by one and adding AbortSignal support. This PR lets you abort an ongoing const controller = new AbortController(); const { signal } = controller; const data = new Uint8Array(Buffer.from('Hello Node.js')); (async () => { try { await fs.writeFile('message.txt', data, { signal }); } catch (err) { // When a request is aborted - err is an AbortError } })(); // When the request should be aborted controller.abort(); Note that unlike
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
benjamingr
force-pushed
the
abort-signal-write-file
branch
from
01d0a51 to
cd7b999
Compare
aduh95
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bacause no backporting and 12.x?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
1 of 2 tasks
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
jasnell
reviewed
Uh oh!
There was an error while loading. Please reload this page.
jasnell
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be a bit difficult, and is likely something that we should tackle later in a separate PR, but it would be helpful if this reported the number of bytes known to have been written at the point of failure/cancelation.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I asked in the description it's actually pretty easy to do - but I remember there were really good arguments regarding whether or not we should do this (in the summit, by @addaleax IIRC) and I don't remember what the conclusion was. Adding the number of bytes written is actually technically pretty easy here if we just want to approximate how much was written since the last
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right – I think we basically agreed to see cancellation is a way of expressing disinterest in the result of an operation. Not reporting the number of written bytes goes in line with that. More importantly, if we add cancellation support to the actual fs operations underneath – as we should – then these numbers become inherently unreliable. I would not be in favour of adding this, if somebody wants it, then they should use
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
jasnell
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Users who are unfamiliar with how writeFile works under the covers may find this sentence confusing.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you propose we deal with this? Add an extra note to writeFile explaining how it works and suggesting a createWriteStream for performacne sensitive stuff like we do with readFile?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to explain how this works underneath instead, and then include the above sentence.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ed7d240 to
1072fc9
Compare
#35993 (comment) PR-URL: #35995 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| if (options.signal && options.signal.aborted) { | |
| if (options.signal?.aborted) { |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
1072fc9 to
017246b
Compare
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 9afe2b6...d9dadac |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
PR-URL: #35993 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
#35993 (comment) PR-URL: #35995 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]>
PR-URL: #35993 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
#35993 (comment) PR-URL: #35995 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]>
#35993 (comment) PR-URL: #35995 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]>
#35993 (comment) PR-URL: #35995 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]>
PR-URL: nodejs#35993 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: #35993 Backport-PR-URL: #38386 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Refs: nodejs#33716 Refs: nodejs#35993 Refs: nodejs#35911
Refs: #33716 Refs: #35993 Refs: #35911 PR-URL: #39972 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
PR-URL: #39972 Refs: #33716 Refs: #35993 Refs: #35911 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Refs: #33716 Refs: #35993 Refs: #35911 PR-URL: #39972 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.