Skip to content

Commit

Permalink
Use threadpool if active (#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmcd committed Apr 30, 2020
1 parent 01cc1d2 commit 47ad53a
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions Sources/Vapor/Passwords/AsyncPasswordHasher.swift
Expand Up @@ -25,15 +25,9 @@ public struct AsyncPasswordHasher {
public func hash<Password>(_ password: Password) -> EventLoopFuture<[UInt8]>
where Password: DataProtocol
{
let promise = self.eventLoop.makePromise(of: [UInt8].self)
self.threadPool.submit { _ in
do {
return promise.succeed(try self.hasher.hash(password))
} catch {
return promise.fail(error)
}
return self.threadPool.runIfActive(eventLoop: self.eventLoop) {
try self.hasher.hash(password)
}
return promise.futureResult
}

public func verify<Password, Digest>(
Expand All @@ -42,15 +36,9 @@ public struct AsyncPasswordHasher {
) -> EventLoopFuture<Bool>
where Password: DataProtocol, Digest: DataProtocol
{
let promise = eventLoop.makePromise(of: Bool.self)
self.threadPool.submit { _ in
do {
return promise.succeed(try self.hasher.verify(password, created: digest))
} catch {
return promise.fail(error)
}
return self.threadPool.runIfActive(eventLoop: self.eventLoop) {
try self.hasher.verify(password, created: digest)
}
return promise.futureResult
}

public func hash(_ password: String) -> EventLoopFuture<String> {
Expand Down

0 comments on commit 47ad53a

Please sign in to comment.