Tried the return Promise pattern and got me here: fs.open(path,'r') .then(fd => fs.write(data)) .then(written => fs.close(/* fd?*/))
@trevnorris @isntitvacant but yeah, I hear you - can't imagine beginners even starting to understand wth is going on
-
-
@yoshuawuyts@trevnorris I wouldn't underestimate beginners. It's about as complicated as any other container type (Arrays, etc) -
@isntitvacant@yoshuawuyts@trevnorris I'm not convinced that an Async state machine is simpler than a primitive. ... - 24 more replies
New conversation -
-
-
@yoshuawuyts@trevnorris@isntitvacant it gets more confusing if you put a promise in the place you want a fn: https://babeljs.io/repl/#?experimental=true&evaluate=true&loose=false&spec=true&code=const%20fd%20%3D%20Promise.resolve(1)%3B%0Aconst%20wrote%20%3D%20fd.then(fd%20%3D%3E%20-1)%3B%0Aconst%20close%20%3D%20wrote.then(fd).then(fd%20%3D%3E%20console.error('fd'%2C%20fd))&playground=false …Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@yoshuawuyts@trevnorris@isntitvacant for beginners: Its just like assigning sync expr to a variable. It gets cached after the first call. -
@yoshuawuyts@trevnorris@isntitvacant Every single thing about JS promises has a corresponding thing in synchronous code.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.