Skip to content

Commit

Permalink
refactoring promise
Browse files Browse the repository at this point in the history
add RequestProfile sample
  • Loading branch information
kosyloa committed Apr 16, 2024
1 parent 29474a7 commit c2f14be
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@
642DC9352AAA21C300974F5C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
642DC9402AAA290300974F5C /* IpfCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IpfCell.swift; sourceTree = "<group>"; };
6433B12C2BCE7ADD004EFED7 /* DXFeed+LastEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DXFeed+LastEvents.swift"; sourceTree = "<group>"; };
6433B1302BCE87D4004EFED7 /* RequestProfile.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = RequestProfile.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
6435EE3C2B1F1E9200E8496C /* PrintQuoteEvents.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = PrintQuoteEvents.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
64437A8E2A9DEE6F005929B2 /* InstrumentProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfile.swift; sourceTree = "<group>"; };
64437A912A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeInstrumentProfileReader.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1097,6 +1098,7 @@
641C64AE2B344E770023CFAD /* PublishProfiles.playground */,
64F9C6C12B4BFD8F003ED014 /* DXFeedconnect.playground */,
644551C92B973A0D0069E3A2 /* FetchDailyCandles.playground */,
6433B1302BCE87D4004EFED7 /* RequestProfile.playground */,
);
path = Playgrounds;
sourceTree = "<group>";
Expand Down
6 changes: 4 additions & 2 deletions DXFeedFramework/Promise/Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ public class Promise {
/// This method waits forever.
/// - Returns: result of computation.
/// - Throws : GraalException. Rethrows exception from Java
public func await() throws {
@discardableResult public func await() throws -> Promise {
_ = try native.await()
return self
}

/// Wait for computation to complete and return its result or throw an exception in case of exceptional completion.
/// If the wait times out, then the computation is ``cancel()`` cancelled and exception is thrown.
/// - Returns: result of computation.
/// - Throws : GraalException. Rethrows exception from Java
public func await(millis timeOut: Int32) throws {
@discardableResult public func await(millis timeOut: Int32) throws -> Promise {
_ = try native.await(millis: timeOut)
return self
}
/// Wait for computation to complete and return its result or throw an exception in case of exceptional completion.
/// If the wait times out, then the computation is ``cancel()`` cancelled and exception is thrown.
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFrameworkTests/DXPromiseTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class DXPromiseTest: XCTestCase {
receivedEventExp.fulfill()
}
}
wait(for: [receivedEventExp], timeout: 1)
wait(for: [receivedEventExp], timeout: 2)

} catch {
XCTAssert(false, "testGetResult \(error)")
Expand Down Expand Up @@ -177,7 +177,7 @@ final class DXPromiseTest: XCTestCase {
}
}
})
wait(for: Array(expectations.values), timeout: 1)
wait(for: Array(expectations.values), timeout: 2)
} catch {
XCTAssert(false, "testGetIndexedEventResult \(error)")
}
Expand Down
10 changes: 10 additions & 0 deletions Samples/Playgrounds/RequestProfile.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Cocoa
import DXFeedFramework

let address = "demo.dxfeed.com:7300"
let symbol = "AAPL"
let endpoint = try DXEndpoint.create().connect(address)
let promise = try endpoint.getFeed()?.getLastEventPromise(type: Profile.self, symbol: symbol)
let profile = try promise?.await(millis: 5000).getResult()
print(profile?.toString())
try endpoint.closeAndAwaitTermination()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

0 comments on commit c2f14be

Please sign in to comment.