@@ -5,28 +5,38 @@ const {
55 createLock
66} = require ( './utils' )
77
8+ // These operations are read-locked at the function level and will execute simultaneously
89const readOperations = {
910 ls : require ( './ls' ) ,
10- read : require ( './read' ) ,
11- readPullStream : require ( './read-pull-stream' ) ,
12- readReadableStream : require ( './read-readable-stream' ) ,
1311 stat : require ( './stat' )
1412}
1513
14+ // These operations are locked at the function level and will execute in series
1615const writeOperations = {
1716 cp : require ( './cp' ) ,
1817 flush : require ( './flush' ) ,
1918 mkdir : require ( './mkdir' ) ,
2019 mv : require ( './mv' ) ,
21- rm : require ( './rm' ) ,
22- write : require ( './write' )
20+ rm : require ( './rm' )
21+ }
22+
23+ // These operations are asynchronous and manage their own locking
24+ const upwrappedOperations = {
25+ write : require ( './write' ) ,
26+ read : require ( './read' )
27+ }
28+
29+ // These operations are synchronous and manage their own locking
30+ const upwrappedSynchronousOperations = {
31+ readPullStream : require ( './read-pull-stream' ) ,
32+ readReadableStream : require ( './read-readable-stream' )
2333}
2434
25- const wrap = ( ipfs , mfs , operations , lock ) => {
35+ const wrap = ( {
36+ ipfs, mfs, operations, lock
37+ } ) => {
2638 Object . keys ( operations ) . forEach ( key => {
27- if ( operations . hasOwnProperty ( key ) ) {
28- mfs [ key ] = promisify ( lock ( operations [ key ] ( ipfs ) ) )
29- }
39+ mfs [ key ] = promisify ( lock ( operations [ key ] ( ipfs ) ) )
3040 } )
3141}
3242
@@ -51,8 +61,20 @@ module.exports = (ipfs, options) => {
5161
5262 const mfs = { }
5363
54- wrap ( ipfs , mfs , readOperations , readLock )
55- wrap ( ipfs , mfs , writeOperations , writeLock )
64+ wrap ( {
65+ ipfs, mfs, operations : readOperations , lock : readLock
66+ } )
67+ wrap ( {
68+ ipfs, mfs, operations : writeOperations , lock : writeLock
69+ } )
70+
71+ Object . keys ( upwrappedOperations ) . forEach ( key => {
72+ mfs [ key ] = promisify ( upwrappedOperations [ key ] ( ipfs ) )
73+ } )
74+
75+ Object . keys ( upwrappedSynchronousOperations ) . forEach ( key => {
76+ mfs [ key ] = upwrappedSynchronousOperations [ key ] ( ipfs )
77+ } )
5678
5779 return mfs
5880}
0 commit comments