mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Use end-of-stream to know when to release lock
This commit is contained in:
parent
230303e7d7
commit
0ffd332828
8
package-lock.json
generated
8
package-lock.json
generated
@ -1180,6 +1180,14 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.9.tgz",
|
||||
"integrity": "sha512-zurD1ibz21BRlAOIKP8yhrxlqKx6L9VCwkB5kMiP6nZAhoF5MvC7qS1qPA7nRcr1GJolfkQC7/EAL4hdYejLtg=="
|
||||
},
|
||||
"@types/end-of-stream": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/end-of-stream/-/end-of-stream-1.4.0.tgz",
|
||||
"integrity": "sha512-d0FD2A4vpFI8wyQeQbr9VDVKtA1PmeGO3Ntn+6j626QTtAQ9HSqWFACP7rTHaV2cspVhLijl00Vvkf/U2UZGWA==",
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/express": {
|
||||
"version": "4.17.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.8.tgz",
|
||||
|
@ -79,6 +79,7 @@
|
||||
"@types/arrayify-stream": "^1.0.0",
|
||||
"@types/async-lock": "^1.1.2",
|
||||
"@types/cors": "^2.8.9",
|
||||
"@types/end-of-stream": "^1.4.0",
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/mime-types": "^2.1.0",
|
||||
"@types/n3": "^1.4.4",
|
||||
@ -94,6 +95,7 @@
|
||||
"async-lock": "^1.2.4",
|
||||
"componentsjs": "^4.0.1",
|
||||
"cors": "^2.8.5",
|
||||
"end-of-stream": "^1.4.4",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"express": "^4.17.1",
|
||||
"fetch-sparql-endpoint": "^1.8.0",
|
||||
|
@ -1,4 +1,6 @@
|
||||
import type { Readable } from 'stream';
|
||||
import { promisify } from 'util';
|
||||
import eos from 'end-of-stream';
|
||||
import type { Patch } from '../ldp/http/Patch';
|
||||
import { BasicRepresentation } from '../ldp/representation/BasicRepresentation';
|
||||
import type { Representation } from '../ldp/representation/Representation';
|
||||
@ -9,6 +11,7 @@ import type { ExpiringReadWriteLocker } from '../util/locking/ExpiringReadWriteL
|
||||
import type { AtomicResourceStore } from './AtomicResourceStore';
|
||||
import type { Conditions } from './Conditions';
|
||||
import type { ResourceStore } from './ResourceStore';
|
||||
const endOfStream = promisify(eos);
|
||||
|
||||
/**
|
||||
* Store that for every call acquires a lock before executing it on the requested resource,
|
||||
@ -121,11 +124,7 @@ export class LockingResourceStore implements AtomicResourceStore {
|
||||
*/
|
||||
protected async waitForStreamToEnd(source: Readable): Promise<void> {
|
||||
try {
|
||||
await new Promise((resolve, reject): void => {
|
||||
source.on('error', reject);
|
||||
source.on('end', resolve);
|
||||
source.on('close', resolve);
|
||||
});
|
||||
await endOfStream(source);
|
||||
} catch {
|
||||
// Destroy the stream in case of errors
|
||||
if (!source.destroyed) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user