Multiple Message Passing Implementation#100
Multiple Message Passing Implementation#100msmollin wants to merge 7 commits intomutualmobile:masterfrom
Conversation
|
|
||
| #pragma mark - MMWormholeTransiting Methods | ||
|
|
||
| - (BOOL)writeMessageObject:(id<NSCoding>)messageObject forIdentifier:(NSString *)identifier { |
There was a problem hiding this comment.
Would you want to pass in an error pointer to find out how it might have failed?
| } else { | ||
| storageArray = [[NSMutableArray alloc] init]; | ||
| } | ||
| [storageArray addObject:messageObject]; |
There was a problem hiding this comment.
Is there a concern that we are storing a reference to the messageObject and someone might later mutate the message? Do we want to prefer a copy of the object here?
| if ([storageArray count] == 0) { | ||
| return nil; | ||
| } | ||
| id messageObject = storageArray[0]; |
There was a problem hiding this comment.
Seems curious that we are making the assumption the array returned for this identifier is always a single item collection. Why are we writing and reading arrays from the file system and not the message object itself?
| NSError *error = nil; | ||
| __block NSData *data = nil; | ||
|
|
||
| [fileCoordinator |
There was a problem hiding this comment.
Seems expensive to read from disk for every call, though I'd probably just make a note of the consideration until it's a measurable issue.
Hello folks! Seems like this library is mostly unmaintained but I figured I'd open this PR for posterity sake incase anyone else needs this.
Issue
The default
MMWormholeFileTransitingand its subclassMMWormholeCoordinatedFileTransitingboth have an inherent issue where they support enqueuing multiple messages across the wormhole, BUT every time a message is enqueued, it overwrites the message payload. So, when attempting to transitNmessage payloads across the wormhole (similar to howNSNotificationCenteror any other message bus construct works), you getNmessages but only the latest written payload.Solution
This doesn't work for my use case unfortunately, so thus I present
MMWormholeManifestFileTransitingfor your inspection and approval. It utilizes the more modern NSFileCoordinator-based approach fromMMWormholeCoordinatedFileTransitingbut instead of just writing the message to disk and thus overwriting whatever is currently there, it manages a stack (NSArray) of messages that need to be sent across the wormhole which are then dispatched FILO style across the wormhole via pushing and popping the stack.There's a few potential improvements / optimizations to be made here: