Async from Sync Dir read

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) ?

You should have access to an EventLoop somewhere so you can do (in Vapor) eventLoop.future(result)

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.

Tell me, where can I find an example with promise for Vapor 4 ?

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

Terms of Service

Privacy Policy

Cookie Policy