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

Added stop func to stop the task early. added async callbacks for Rea… #18

Merged
merged 2 commits into from
Apr 28, 2016
Merged

Added stop func to stop the task early. added async callbacks for Rea… #18

merged 2 commits into from
Apr 28, 2016

Conversation

kenthinson
Copy link
Contributor

This look ok?

…dableStream.onOutput and AsyncShellTask.onCompletion allows for getting callbacks with data as the AsyncShellTask is running.
@kareman
Copy link
Owner

kareman commented Apr 26, 2016

/** Callback with when ReadableStream has data.*/
extension ReadableStream {
    public func onOutput ( handler: ((String) -> ())? ) {
        if let h = handler{
            filehandle.readabilityHandler = {(NSFileHandle) in
                if let output = self.readSome(){
                    h(output)
                }
            }
        }
    }
}         
I figured if you are trying to get this callback you are after the string that is currently in the buffer? Again I might be overlooking something :/

Yes in most cases this will be true. But I would still like to leave that decision to the SwiftShell users. Maybe they would like to call readSome several times if they don't get enough output on the first try, or to check if the end has been reached. Maybe they need to get everything at once with read. And in rare cases they may want to just be notified that there is some output without actually fetching the output.

@kareman
Copy link
Owner

kareman commented Apr 27, 2016

but you can rename the method above to onStringOutput or something like that and use that as a shortcut. I suspect most of the time people will be using that function instead of onOutput.

@kenthinson
Copy link
Contributor Author

That's a good idea. I've got a lot of homework this week , and my mom just had spine surgery so I'm helping her around the house. so I'm not sure when I'll have time to put together another pull request.

Sent from my iPhone

On Apr 27, 2016, at 5:46 AM, Kare Morstol notifications@github.com wrote:

but you can rename the method above to onStringOutput or something like that and use that as a shortcut. I suspect most of the time people will be using that function instead of onOutput.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

@kareman kareman merged commit 34e7e06 into kareman:master Apr 28, 2016
@kareman
Copy link
Owner

kareman commented Apr 28, 2016

No problem, I just added some indentation, unit tests and documentation and merged your commits into master. Thanks again for the great work 👍 .

@kareman
Copy link
Owner

kareman commented Apr 28, 2016

And I hope your mother gets better soon.

@kenthinson
Copy link
Contributor Author

Thanks :)

Sent from my iPhone

On Apr 27, 2016, at 6:04 PM, Kare Morstol notifications@github.com wrote:

And hope your mother gets better soon.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

kareman added a commit that referenced this pull request Apr 27, 2017
Now I vaguely recall it was there for a reason.

```
$ swift build
Compile Swift Module 'SwiftShell' (9 sources)
swift: /home/buildnode/disk2/workspace/oss-swift-3.1-package-linux-ubuntu-14_04/swift/lib/Sema/CSApply.cpp:5990: swift::Expr *(anonymous namespace)::ExprRewriter::coerceObjectArgumentToType(swift::Expr *, swift::Type, swift::ValueDecl *, swift::AccessSemantics, swift::constraints::ConstraintLocatorBuilder): Assertion `fromType->is<LValueType>() && "Can only convert lvalues to inout"' failed.
#0 0x000000000335ffe8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x335ffe8)
#1 0x0000000003360b86 SignalHandler(int) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x3360b86)
#2 0x00007f239201c330 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#3 0x00007f2390a07c37 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x36c37)
#4 0x00007f2390a0b028 abort (/lib/x86_64-linux-gnu/libc.so.6+0x3a028)
#5 0x00007f2390a00bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x2fbf6)
#6 0x00007f2390a00ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#7 0x00000000010a306a (anonymous namespace)::ExprRewriter::coerceObjectArgumentToType(swift::Expr*, swift::Type, swift::ValueDecl*, swift::AccessSemantics, swift::constraints::ConstraintLocatorBuilder) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x10a306a)
#8 0x000000000109b0cc (anonymous namespace)::ExprRewriter::buildMemberRef(swift::Expr*, swift::Type, swift::SourceLoc, swift::ValueDecl*, swift::DeclNameLoc, swift::Type, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder, bool, swift::FunctionRefKind, swift::AccessSemantics, bool) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x109b0cc)
#9 0x00000000010a8c3f swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x10a8c3f)
#10 0x0000000001099314 (anonymous namespace)::ExprRewriter::walkToExprPost(swift::Expr*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x1099314)
#11 0x00000000010b11b1 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x10b11b1)
#12 0x000000000128901c (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x128901c)
#13 0x000000000128303b swift::Expr::walk(swift::ASTWalker&) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x128303b)
#14 0x00000000010960f2 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x10960f2)
#15 0x00000000011604ff swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x11604ff)
#16 0x000000000107af20 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x107af20)
#17 0x000000000107b219 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x107b219)
#18 0x000000000107ae4c swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x107ae4c)
#19 0x0000000001079ad5 (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x1079ad5)
#20 0x0000000001078dad swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x1078dad)
#21 0x0000000001078c05 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x1078c05)
#22 0x000000000107981c swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x107981c)
#23 0x000000000108fc08 typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x108fc08)
#24 0x00000000010908a1 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x10908a1)
#25 0x0000000000e0fe4a swift::CompilerInstance::performSema() (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0xe0fe4a)
#26 0x0000000000475eed swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x475eed)
#27 0x000000000043bbe4 main (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x43bbe4)
#28 0x00007f23909f2f45 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f45)
#29 0x00000000004395a0 _start (/home/travis/.swiftenv/versions/3.1/usr/bin/swift+0x4395a0)
Stack dump:
0.	Program arguments: /home/travis/.swiftenv/versions/3.1/usr/bin/swift -frontend -c /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/FileHandle.swift /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/String.swift /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Bash.swift /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Context.swift /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Files.swift /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Command.swift /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/General/Array.swift -primary-file /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Stream/Stream.swift /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Stream/Lazy-split.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/travis/build/kareman/SwiftShell/.build/debug -enable-testing -g -module-cache-path /home/travis/build/kareman/SwiftShell/.build/debug/ModuleCache -D SWIFT_PACKAGE -emit-module-doc-path /home/travis/build/kareman/SwiftShell/.build/debug/SwiftShell.build/Stream~partial.swiftdoc -Onone -parse-as-library -module-name SwiftShell -emit-module-path /home/travis/build/kareman/SwiftShell/.build/debug/SwiftShell.build/Stream~partial.swiftmodule -emit-dependencies-path /home/travis/build/kareman/SwiftShell/.build/debug/SwiftShell.build/Stream.d -emit-reference-dependencies-path /home/travis/build/kareman/SwiftShell/.build/debug/SwiftShell.build/Stream.swiftdeps -num-threads 8 -o /home/travis/build/kareman/SwiftShell/.build/debug/SwiftShell.build/Stream/Stream.swift.o
1.	While type-checking 'write' at /home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Stream/Stream.swift:89:9
2.	While type-checking expression at [/home/travis/build/kareman/SwiftShell/Sources/SwiftShell/Stream/Stream.swift:90:38 - line:90:55] RangeText="target.write(text)"
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants