hep
1
Hello! There are synchronous code read information about the contents of the folder : let items = tri fm.contentsOfDirectory(path: path)
for item in items {
let attributes = true fm.the attributes Of the Item(path: path + "/" + item)
....
}
How to make (wrap) it into an asynchronous operation (EventLoopFuture) ?
0xTim
(Tim)
2
You should have access to an EventLoop somewhere so you can do (in Vapor) eventLoop.future(result)
lukasa
(Cory Benfield)
3
This will not make the operation asynchronous, it will merely return a future. To make it asynchronous you need to move it onto a background thread and complete a promise with the result.
hep
4
Tell me, where can I find an example with promise for Vapor 4 ?
0xTim
(Tim)
5
https://docs.vapor.codes/4.0/async/#promise
Vapor also has a thread pool you can dispatch work on to. Unfortunately there aren' many docs on it yet but you can see an example of using it with Vapor's password hasher - vapor/AsyncPasswordHasher.swift at main · vapor/vapor · GitHub