Does anyone have better resources that explains Future and Promise than chapter 4?

Hi,

I find the explanation of Future and Promise to be a bit weak in this book. Does anyone have better resources to learn about Future and Promise? I have already read the official documentation on Vapor’s official website.

Thanks.

1 Like

@blakninja Please check out this thread when you get a chance:

I hope it helps!

1 Like

Yes it helps, thank you.

1 Like

Does anyone know in what context does the code snippet on page 49 fit into?

The code starts with “return database”, but where does it fit in the big picture? Is it inside a function? What is the function signature?

The code i’m referring to:

// 1
return database
.getAllUsers()
.flatMap(to: HTTPStatus.self) { users in
// 2
let user = users[0]
user.name = "Bob"
// 3
return user.save().map(to: HTTPStatus.self) { user in
//4
return HTTPStatus.noContent
}
}

Thanks.

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

@blakninja yes that would be inside a request handler basically - it’s more pseudo code to demonstrate how futures work. But you could have a function signature for it that looks like:

func updateFirstUser(on database: Database) throws -> Future<HTTPStatus>

That helps, thanks! For me, it always help to have an example of context where the pseudocode can be used.