Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift 2.3] Add @noescape to appropriate closures, matching the Swift3 branch's behavior #130

Merged
merged 1 commit into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions GRDB/Core/DatabasePool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ extension DatabasePool : DatabaseReader {
///
/// - parameter block: A block that accesses the database.
/// - throws: The error thrown by the block.
public func read<T>(block: (db: Database) throws -> T) rethrows -> T {
public func read<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
// The block isolation comes from the DEFERRED transaction.
// See DatabasePoolTests.testReadMethodIsolationOfBlock().
return try readerPool.get { reader in
Expand Down Expand Up @@ -317,7 +317,7 @@ extension DatabasePool : DatabaseReader {
///
/// - parameter block: A block that accesses the database.
/// - throws: The error thrown by the block.
public func nonIsolatedRead<T>(block: (db: Database) throws -> T) rethrows -> T {
public func nonIsolatedRead<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
return try readerPool.get { reader in
try reader.performSync { db in
try block(db: db)
Expand Down Expand Up @@ -401,7 +401,7 @@ extension DatabasePool : DatabaseWriter {
///
/// - parameter block: A block that accesses the database.
/// - throws: The error thrown by the block.
public func write<T>(block: (db: Database) throws -> T) rethrows -> T {
public func write<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
return try writer.performSync(block)
}

Expand All @@ -426,7 +426,7 @@ extension DatabasePool : DatabaseWriter {
/// - block: A block that executes SQL statements and return either
/// .Commit or .Rollback.
/// - throws: The error thrown by the block.
public func writeInTransaction(kind: TransactionKind? = nil, _ block: (db: Database) throws -> TransactionCompletion) throws {
public func writeInTransaction(kind: TransactionKind? = nil, @noescape _ block: (db: Database) throws -> TransactionCompletion) throws {
try writer.performSync { db in
try db.inTransaction(kind) {
try block(db: db)
Expand Down
10 changes: 5 additions & 5 deletions GRDB/Core/DatabaseQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public final class DatabaseQueue {
///
/// - parameter block: A block that accesses the database.
/// - throws: The error thrown by the block.
public func inDatabase<T>(block: (db: Database) throws -> T) rethrows -> T {
public func inDatabase<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
return try serializedDatabase.performSync(block)
}

Expand All @@ -104,7 +104,7 @@ public final class DatabaseQueue {
/// - block: A block that executes SQL statements and return either
/// .Commit or .Rollback.
/// - throws: The error thrown by the block.
public func inTransaction(kind: TransactionKind? = nil, _ block: (db: Database) throws -> TransactionCompletion) throws {
public func inTransaction(kind: TransactionKind? = nil, @noescape _ block: (db: Database) throws -> TransactionCompletion) throws {
try serializedDatabase.performSync { db in
try db.inTransaction(kind) {
try block(db: db)
Expand Down Expand Up @@ -223,14 +223,14 @@ extension DatabaseQueue : DatabaseReader {
/// Alias for inDatabase
///
/// This method is part of the DatabaseReader protocol adoption.
public func read<T>(block: (db: Database) throws -> T) rethrows -> T {
public func read<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
return try serializedDatabase.performSync(block)
}

/// Alias for inDatabase
///
/// This method is part of the DatabaseReader protocol adoption.
public func nonIsolatedRead<T>(block: (db: Database) throws -> T) rethrows -> T {
public func nonIsolatedRead<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
return try serializedDatabase.performSync(block)
}

Expand Down Expand Up @@ -300,7 +300,7 @@ extension DatabaseQueue : DatabaseWriter {
/// Alias for inDatabase
///
/// This method is part of the DatabaseWriter protocol adoption.
public func write<T>(block: (db: Database) throws -> T) rethrows -> T {
public func write<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
return try serializedDatabase.performSync(block)
}

Expand Down
4 changes: 2 additions & 2 deletions GRDB/Core/DatabaseReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public protocol DatabaseReader : class {
///
/// - parameter block: A block that accesses the database.
/// - throws: The error thrown by the block.
func read<T>(block: (db: Database) throws -> T) rethrows -> T
func read<T>(@noescape block: (db: Database) throws -> T) rethrows -> T

/// Synchronously executes a read-only block that takes a database
/// connection, and returns its result.
Expand All @@ -77,7 +77,7 @@ public protocol DatabaseReader : class {
/// let int1 = Int.fetchOne(db, sql)
/// let int2 = Int.fetchOne(db, sql)
/// }
func nonIsolatedRead<T>(block: (db: Database) throws -> T) rethrows -> T
func nonIsolatedRead<T>(@noescape block: (db: Database) throws -> T) rethrows -> T


// MARK: - Functions
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Core/DatabaseWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public protocol DatabaseWriter : DatabaseReader {
///
/// The *block* argument is completely isolated. Eventual concurrent
/// database updates are postponed until the block has executed.
func write<T>(block: (db: Database) throws -> T) rethrows -> T
func write<T>(@noescape block: (db: Database) throws -> T) rethrows -> T


// MARK: - Reading from Database
Expand Down
8 changes: 4 additions & 4 deletions GRDB/Core/SerializedDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class SerializedDatabase {
/// its result.
///
/// This method is *not* reentrant.
func performSync<T>(block: (db: Database) throws -> T) rethrows -> T {
func performSync<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
// Three diffent cases:
//
// 1. A database is invoked from some queue like the main queue:
Expand Down Expand Up @@ -106,7 +106,7 @@ final class SerializedDatabase {
// currently allowed databases inside.
//
// The impl function helps us turn dispatch_sync into a rethrowing function
func impl(queue: dispatch_queue_t, db: Database, block: (db: Database) throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
func impl(queue: dispatch_queue_t, db: Database, @noescape block: (db: Database) throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
var result: T? = nil
var blockError: ErrorType? = nil
dispatch_sync(queue) {
Expand Down Expand Up @@ -141,7 +141,7 @@ final class SerializedDatabase {
// Just dispatch block to queue:
//
// The impl function helps us turn dispatch_sync into a rethrowing function
func impl(queue: dispatch_queue_t, db: Database, block: (db: Database) throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
func impl(queue: dispatch_queue_t, db: Database, @noescape block: (db: Database) throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
var result: T? = nil
var blockError: ErrorType? = nil
dispatch_sync(queue) {
Expand Down Expand Up @@ -170,7 +170,7 @@ final class SerializedDatabase {
/// Executes the block in the current queue.
///
/// - precondition: the current dispatch queue is valid.
func perform<T>(block: (db: Database) throws -> T) rethrows -> T {
func perform<T>(@noescape block: (db: Database) throws -> T) rethrows -> T {
preconditionValidQueue()
return try block(db: db)
}
Expand Down
12 changes: 6 additions & 6 deletions GRDB/Core/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func GRDBPrecondition(@autoclosure condition: () -> Bool, @autoclosure _ message

/// A function declared as rethrows that synchronously executes a throwing
/// block in a dispatch_queue.
func dispatchSync<T>(queue: dispatch_queue_t, _ block: () throws -> T) rethrows -> T {
func impl(queue: dispatch_queue_t, block: () throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
func dispatchSync<T>(queue: dispatch_queue_t, @noescape _ block: () throws -> T) rethrows -> T {
func impl(queue: dispatch_queue_t, @noescape block: () throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
var result: T? = nil
var blockError: ErrorType? = nil
dispatch_sync(queue) {
Expand Down Expand Up @@ -131,15 +131,15 @@ final class ReadWriteBox<T> {
self.queue = dispatch_queue_create("GRDB.ReadWriteBox", DISPATCH_QUEUE_CONCURRENT)
}

func read<U>(block: (T) -> U) -> U {
func read<U>(@noescape block: (T) -> U) -> U {
var result: U? = nil
dispatch_sync(queue) {
result = block(self._value)
}
return result!
}

func write(block: (inout T) -> Void) {
func write(@noescape block: (inout T) -> Void) {
dispatch_barrier_sync(queue) {
block(&self._value)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ final class Pool<T> {

/// Performs a block on each pool element, available or not.
/// The block is run is some arbitrary queue.
func forEach(block: (T) throws -> ()) rethrows {
func forEach(@noescape block: (T) throws -> ()) rethrows {
try dispatchSync(queue) {
for item in self.items {
try block(item.element)
Expand All @@ -230,7 +230,7 @@ final class Pool<T> {

/// Empty the pool. Currently used items won't be reused.
/// Eventual block is executed before any other element is dequeued.
func clear(block: () throws -> ()) rethrows {
func clear(@noescape block: () throws -> ()) rethrows {
try dispatchSync(queue) {
self.items = []
try block()
Expand Down